Monday, September 13, 2021

example of a while loop that simply prints out the numbers 1, 2, 3, 4, 5:

 



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

int number; // The number to be printed.

number = 1; // Start with 1.

while ( number < 6 )
{ // Keep going as long as number is < 6.

System.out.println(number);

number = number + 1; // Go on to the next number.
}

System.out.println("Done!");

}

}








































No comments:

Post a Comment

Contact Us

Contact Form

Name

Email *

Message *