Advertisement
hpilo

Chapter4_Loops_Ex6

Dec 15th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. import java.util.Scanner;
  2. /*
  3.     =====================================================
  4.                    chapter 4: Loops
  5.  
  6.       Ex6: new number contains also reversed number
  7.     =====================================================
  8. */
  9.  
  10. public class MyProgram {
  11.     public static void main(String[] args) {
  12.  
  13.         int num,count=0;
  14.         int tmp,newNum=0;
  15.         Scanner s=new Scanner(System.in);
  16.  
  17.         System.out.println("Enter a number: ");
  18.         num=s.nextInt();
  19.         tmp=num;
  20.  
  21.         while(tmp>0){
  22.             newNum*=10;
  23.             newNum+=tmp%10;
  24.  
  25.             tmp/=10;
  26.             count++;
  27.         }
  28.         System.out.println(newNum);
  29.         tmp= (int) Math.pow(10,count);
  30.         tmp*=num;
  31.         newNum+=tmp;
  32.         System.out.println(newNum);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement