While Loop – Exercise

While Loop – Exercise

Neso Academy

4 года назад

79,264 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@Absalatreal
@Absalatreal - 08.10.2023 12:19

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

boolean isTrue = false;
System.out.print("Enter a number between 1 and 10: ");
while (!isTrue) {
int num = input.nextInt();
if (num < 1 || num > 10) {
System.out.println(num + " is not between 1 and 10. Please try again.");
} else {
System.out.println(num + " is between 1 and 10. Thank you!");
isTrue = true;
}
}
}
}

Ответить
@Atanepes
@Atanepes - 04.07.2023 14:25

2morrow I have exam from Java And I found this channel very helpful. I will study after exams too ❤thanks Neso

Ответить
@bndrsoud2876
@bndrsoud2876 - 12.05.2023 14:54

Greatest

Ответить
@smallwise1
@smallwise1 - 10.04.2023 02:41

Great! Thank you <3

Ответить
@qusaiclasher4452
@qusaiclasher4452 - 13.02.2023 08:56

You are a legend. Please continue making useful videos

Ответить
@Musicsection66
@Musicsection66 - 21.01.2023 19:44

I solved it in this way:

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
int number = '\0';
Scanner s = new Scanner(System.in);

do {
System.out.println("Enter a number!");
number = s.nextInt();

if(number > 0 && number < 11) {
System.out.println(number + " is between 1 and 10.");
} else {
System.out.println(number + " is not between 1 and 10. Try again!");
}
} while (!(number > 0 && number < 11));
System.out.println("Game over");
}
}

Ответить
@shivbaboo3491
@shivbaboo3491 - 09.08.2022 15:52

sir why you are using "||" (or)operator and not using "&&" operator in while() condition.

Ответить
@vovantiensy4940
@vovantiensy4940 - 02.08.2022 05:21

Below is my stupid code:
import java.util.Scanner;

public class test1 {
public static void main(String[] args) {
{
Scanner input = new Scanner(System.in);
System.out.println("Enter your favorite number between 1 and 10");
int n1 = input.nextInt();
while(n1<1 || n1>10){
System.out.println("you're not listening, try again");
n1=input.nextInt();
}
System.out.println("ok good");
}
}
}

Ответить
@kzzazzip6272
@kzzazzip6272 - 07.07.2022 17:19

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Give num 1-10: ");
int inp = scanner.nextInt();
if (inp <= 10 && inp >= 0) {
System.out.println("Inp was " + inp);
} else {
System.out.println("Inp was not in range of 1 and 10");
}
}
}

Ответить
@thatsdeep7058
@thatsdeep7058 - 16.06.2022 00:58

int user = 0;
while (!(user > 1 && user < 10)) {
user = s.nextInt();
if (user > 1 && user < 10) {
System.out.println(user + " is between 1 and 10");
} else
System.out.println(user + " is not betwen 1 and 10");
System.out.println("TRY AGAIN");
}

Ответить
@thivagarmurugan2955
@thivagarmurugan2955 - 01.04.2022 12:36

public static void main (String args[])
{
Scanner num=new Scanner(System.in);


while (true)
{
System.out.println("enter the number between 1 and 10");
int n=num.nextInt();
if (n>10 || n<0)
{
System.out.println("please enter the correct number");
n=num.nextInt();
}
else
{
System.out.println(n +" "+"is between 1 and 10 thanks!");
break;
}

}

Ответить
@ayushimukherjee7227
@ayushimukherjee7227 - 17.03.2022 07:43

package ayushi;

import java.util.Scanner;

public class Main {
public static void main(String[] arg) {
   Scanner intput = new Scanner(System.in);
   System.out.println("enter your number:");
   int a =intput.nextInt();
   while (1<a && a<10){
       System.out.println(a + "is in between 1 and 10");
       a =intput.nextInt();
   }

   System.out.println(a + "is in not between 1 and 10");

}
}

Ответить
@fahad-qx6mw
@fahad-qx6mw - 04.03.2022 19:41

يعطيك العافيه 😍😍

Ответить
@jackrussel891
@jackrussel891 - 31.12.2021 22:29

Why if I do not write this line in the while body, it becomes a loop? Or how is it possible that simply writing this line, it stops the while loop? n = s.nextInt();

Ответить
@drigoephesienalovingson2758
@drigoephesienalovingson2758 - 11.09.2021 00:35

thank you!

Ответить
@hikmathasanov
@hikmathasanov - 01.09.2021 00:48

Excellent lecture. This is my code, which worked, continuing to watch your solution:

public class Main {

public static void main(String[] args) {
System.out.print("enter a number between 1 and 10: ");
Scanner number = new Scanner(System.in);
int f = number.nextInt();
while (f<1 || f>10) {
System.out.print(f + " is not between 1 and 10. Try again: ");
f = number.nextInt();
}
System.out.println(f + " is between 1 and 10. Thanks!");
}
}

Ответить
@taxiservice5786
@taxiservice5786 - 09.08.2021 16:53

what if we enter 1 or 10 ?
it shows us this no is between 1 to 10

Ответить
@swarnenduchakraborty3388
@swarnenduchakraborty3388 - 15.06.2021 18:52

cant we use another variable i with n?

Ответить
@manar7107
@manar7107 - 16.11.2020 21:10

Thanks

Ответить
@nasuu5937
@nasuu5937 - 11.09.2020 09:03

import java.util.Scanner;
public class Program
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int num;

System.out.println("Enter a number between 1-10:");
num = in.nextInt();
if(num<=10){
System.out.println("Nice " num + " is between 1-10 thanks");
}
else{
System.out.println(num + " is not 1 - 10 Try again dumbass");
}
}
}

Ответить
@nxtgaming209
@nxtgaming209 - 13.07.2020 16:08

I think you should use && inside the while loop

Ответить
@nehal2192
@nehal2192 - 10.05.2020 17:26

The way Neso Academy explaining concepts is Excellent.

Ответить
@whatsapwhatsapp662
@whatsapwhatsapp662 - 04.05.2020 00:34

thank you

Ответить
@johnwhite2031
@johnwhite2031 - 28.04.2020 14:54

😎 A1 content, just subbed! Did you check followsm . c o m?! It’s the best way to promote your videos!

Ответить
@samiulfahad2940
@samiulfahad2940 - 16.04.2020 00:33

import java.util.Scanner;

public class Main {
public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
System.out.println("Enter a numbre between 1=10");
int a = sc.nextInt();
while (true) {
if (a < 11 && a > 0) {
System.out.println("Thanks");
break;
}
else {
System.out.println("Try again");
a=sc.nextInt();
}
}
}
}

Ответить
@bsaikumarreddy1413
@bsaikumarreddy1413 - 18.03.2020 19:22

please upload videos fast

Ответить
@GauravKumar-lp6so
@GauravKumar-lp6so - 18.03.2020 15:18

Plz made video on Feedback Amplifier

Ответить
@ShahNawaz-cx3pi
@ShahNawaz-cx3pi - 17.03.2020 23:29

Hello neso academy, I am waiting for Data structure course. Please tell me release date.

Ответить
@leonetechsports5433
@leonetechsports5433 - 17.03.2020 18:02

Realness
thanks very much for all the JAVA tutorials

Ответить
@suheabkhan2546
@suheabkhan2546 - 17.03.2020 17:41

East or west our neso java sir is the best....

Ответить
@JavaAidTutorials
@JavaAidTutorials - 17.03.2020 17:31

Awesome 🔥🔥🔥❤️🔥🔥❤️🔥❤️🔥

Ответить