package conditionalStatements; public class ElseIfClass { public static void main(String[] args) { int a = 20; if(a <= 10) { System.out.println("Number is less then 10"); }else if(a > 10 && a <= 20) { System.out.println("Number is between 10 to 30"); } else if(a > 20 && a <= 30) { System.out.println("Number is between 20 to 30"); } else { System.out.println("Number is greater then 30"); } } }
package whileLoops; import java.util.Scanner; public class SumOfDigits { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int temp = n; int sum = 0; while(temp >0) { int lastDigit = temp%10; temp /= 10; sum += lastDigit; System.out.println(" Last Digit " + lastDigit + " temp " + temp + " Sum " + sum); } System.out.println("The sum of all digit of " + n + " is " + sum); } }
Comments
Post a Comment