Posts

Showing posts with the label while loop

22. Reverse the number and find number is Pallindrome or not.

Pallindrome Number : - If the reverse of the number is eqal to original number then , the number is pallindrome. ex:- original number = 121 , reverse number = = 121 therefore 121 is pallindrome. int r , n ; int rev = 0 ; Scanner sc = new Scanner( System . in ) ; n = sc .nextInt() ; int number = n ; // to not lost original number while ( n > 0 ) { r = n % 10 ; rev = rev * 10 + r ; n = n / 10 ; } System . out .println( rev ) ; if ( rev == number ) { System . out .println( "Number is pallindrome" ) ; } else System . out .println( "Number is not pallindrome" ) ;   output :-                        121                                121                                Number is pallindrome

while loop in java.

1. 1 2 3 4 5 6 7 8 9 10 int i = 1 ; while ( i <= 10 ) { System . out . println ( i ); i ++ ; } Q2. What will be output of this program. int x = 4 , y , z ; y =-- x ; z = x -- ; System . out . println ( x ); System . out . println ( y ); System . out . println ( z ); output:- 2 3 3 Q3. What will be output of this program. int x = 4 , y = 3 , z ; z = x -- - y ; System . out . println ( x ); System . out . println ( y ); System . out . println ( z ); output:- 3 3 1 Q4. What will be output of this program. package com.company ; import java.util.Scanner ; public class Main { public static void main ( String [] args ) { double i = 1.1 ; while ( i == 1.1 ) { System . out . println ( i ); i = i - 0.1 ; } } } output:- 1.1