Learn Programming in Java - Lesson 11 : While Loops

preview_player
Показать описание
Lesson 11 pick up where lesson 10 left off - exploring iterative structures in Java. This time we look at the while loop first by comparing / contrasting it to the for loop, and then by showing you its flexibility. We'll demonstrate the three common loop patterns the pre-test, post-test and mid-test by writing the same program 3 different ways.
Рекомендации по теме
Комментарии
Автор

Thank you Michael, you are great :) Well done and best regards for you.

Osman.Kozlica
Автор

Great Video about while loop very good!

triciaelisaquinoblanca
Автор

Why if youre using 'printf' in the following while loop is it returning a new line after each guess?
while (attempt < 10) {
System.out.printf("Attempt %d : Your Guess ==> ", attempt);
guess = input.nextInt();
attempt++;
}

paamalamadingdong
Автор

Can we modify the program such that if we type a number which we already typed before, will show a message "You have already guessed the number."     ??

smithcodes
Автор

Hi my random generator=new generator (); there is a red underline of random is there any import for random???

guitarismylife
Автор

How to stop incrementing an attempt after a particular point.

I finally i want to say that you took this much attempts. But it keeps incrementing.
here is the code:

package whileloop;

import java.util.Random;
import java.util.Scanner;


public class Whileloop {


public static void main(String[] args) {
Scanner input= new Scanner(System.in);
Random generator=new Random();
int attempt=1;
int
int guess=0;
System.out.println(comguess);

do{
System.out.printf("Attempt %d, I guessed a number. Can you find it? \n", attempt);
guess=input.nextInt();

attempt++;
}while(guess!=comguess);
System.out.printf("Correct! You took %d attempts! \n", attempt);

}

}

sriharisridhar
Автор

Hi Michael, please i have a question regarding this code. int number = generator.nextInt(10) +1; What is the function of +1?

johnkings
Автор

7:43 No! This is not between 1 and 10, this is between 1 and

umnikos
welcome to shbcf.ru