WHILE LOOPS in Java are easy ♾️

preview_player
Показать описание
#java #javatutorial #javacourse

00:00:00 introduction
00:01:40 example 1
00:02:45 infinite loop example
00:03:52 example 2
00:06:40 example 3
00:08:53 do while loop
00:09:53 example 4

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

// EXAMPLE 1

String name = "";

}

// EXAMPLE 2

String response = "";

}

}
}
Рекомендации по теме
Комментарии
Автор

import java.util.Scanner;

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

Scanner scanner = new Scanner(System.in);

// EXAMPLE 1

String name = "";

while(name.isEmpty()){
System.out.print("Enter your name: ");
name = scanner.nextLine();
}

System.out.println("Hello " + name);

// EXAMPLE 2

String response = "";


System.out.print("Press Q to quit: ");
response =
}

System.out.println("You have quit");

// EXAMPLE 3

int age = 0;

do{
System.out.println("Your age can't be negative");
System.out.print("Enter your age: ");
age = scanner.nextInt();
}while(age < 0);

System.out.println("You are " + age + " years old");

// EXAMPLE 4

int number = 0;

do{
System.out.print("Enter a number between 1-10: ");
number = scanner.nextInt();
}while(number < 1 || number > 10);

System.out.println("You picked number: " + number);

scanner.close();
}
}

BroCodez
Автор

Thanks for making this videos. You are helping me to get through my first university exams.

BroccoLovoTV