The java program given below will check the numbers between 1-100 whether it is divisible by 5 or not. After execution there will be displayed those numbers only what are divisible by 5.
This program is almost same to the last two programs. A while-do loop is being used to check the numbers one by one divisible by 5 or not. Mainly the if statement is checking the numbers of the loop before printing.
public class Divi5{ public static void main(String arg []){ //a simple message System.out.println("The numbers divisible by 5 are:"); //initializing integer type variable i int i=1; //do...while loop do{ //if statement to check the numbers for remainder if(i%5==0){ //displaying the expected numbers System.out.print(i+", "); } i++; } while (i<=100);//condition for do...while loop //for two line break System.out.println("\n\n"); } }
No comments:
Post a Comment