DO-WHILE ======== Syntax: initialization; do { statement-1; statement-2; update; } while(condition); while: ===== initialization while(condition) { statements; update; } loop entry control ==> while loop exit control ==> do-while class DoWhileLoop{ public static void main(String[] args) { // initialization for do while int i = 10; do{ System.out.println(i); --i; }while(i >= 1); } } =============================================== // WAP TO FIND THE SUM OF DIGITS OF A NUMBER. /* 12345 1 2 3 4 5 1+2+3+4+5 15 */ import java.util.Scanner; class sumOfDigits{ public static void main(String x[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter a number:"); int num = sc.nextInt();//9876 int n = num; // initialization int ind_dig, s_dig = 0; do{ ind_dig = n % 10; // inidividual digits of a number 6 7 8 9 s_dig = s_dig + ind_dig; // 6 13 21 30 n = n/10;// 987 98 9 0 } while(n != 0); System.out.println("The sum of digits = "+s_dig); } } ===================================== // WAP TO REVERSE THE NUMBER. // 987 ==> 789 import java.util.Scanner; class reverseNumber{ public static void main(String[] arg) { Scanner sco = new Scanner(System.in); System.out.println("Enter a value:"); int num = sco.nextInt(); int i = num; // initialization 9876 int ind_dig,reverse = 0; while(i > 0) { ind_dig = i % 10; //6 7 8 9 reverse = reverse * 10 + ind_dig; //6 67 678 6789 i = i / 10; //987 98 9 0 } System.out.println("The Number after the reverse operation is = "+reverse); } } ============================================================== Assignment: =========== 1) WAP TO CHECK WHETHER THE GIVEN NUMBER IS PALINDROME NUMBER OR NOT. HINT: if(reverse == number) palindrome else not a palindrome 2) WAP TO COUNT THE NUMBER OF DIGITS OF A NUMBER USING DO-WHILE ======================================================= for loop: ======== Syntax_1: for(initialization; condition; update) { loop body statements; } // WAP TO PRINT SUM OF ALL MULTIPLES OF 6 FROM 1 TO 100 USING FOR LOOP. // Syntax_1 class sixMultiples{ public static void main(String args[]) { int s_mul = 0; for(int i = 1;i <= 100;i+=1) { if(i % 6 == 0) { s_mul += i; //6 } } System.out.println("The sum of multiples of six = "+s_mul); } } Syntax_2: initialization; for(;condition; update) { loop body statements; } // WAP TO PRINT ALL MULTIPLES OF 11 FROM 100 1 class multiplesOfEleven{ public static void main(String x[]) { int i = 100; for(;i > 0;--i) { if(i % 11 == 0) { System.out.println(i); } } } } Syntax_3: initialization for(;condition;) { loop body statements; update; } // WAP TO PRINT ALL MULTIPLES OF 11 FROM 100 1 class multiplesOfEleven{ public static void main(String x[]) { int i = 100; for(;i > 0;) { if(i % 11 == 0) { System.out.println(i); } --i; } } }