program on break apart a number in java
program on break apart a number in java
/* this is a program on break apart a number by using this we can break number into its components */ import java.util.Scanner; class BreakApart { public static void main ( String s[] ) { System.out.println( " the number is : " ); int number = new Scanner (System.in ).nextInt(); int remainder ; int i = 1; while( number!=0) { remainder = number%10; System.out.println ( " the " +i +"st value is "+ remainder ); number = number/10; i++; } System.out.println("code to generate the reverse of a number"); int reverse = 0 ; number = new Scanner (System.in ).nextInt(); while ( number!=0) { remainder = number%10; reverse = reverse *10 + remainder ; number = number/10; } System.out.println (" the reverse of the" + number+ " is " + reverse ); } }