Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /*
- =====================================================
- chapter 4: Loops
- Ex5: change digits place
- =====================================================
- */
- public class MyProgram {
- public static void main(String[] args) {
- //variables
- int num,tmp,count=1;
- int newNum=0;
- int twoDig;
- Scanner s=new Scanner(System.in);
- //user input
- System.out.println("Enter a number: ");
- num=s.nextInt();
- tmp=num; //keeping the num intact
- while(tmp/10>0){
- twoDig=tmp%100;
- twoDig=(twoDig%10)*10+(twoDig/10);
- newNum+= twoDig*count;
- tmp/=100;
- count*=100;
- }
- if(tmp>0)
- newNum+=(tmp%10)*count;
- System.out.println("old: "+num+" new: "+newNum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement