Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /*
- =====================================================
- chapter 4: Loops
- Ex10: partition number
- =====================================================
- */
- public class MyProgram {
- public static void main(String[] args) {
- int num,digit,k,location=1;
- int newNum=0;
- int tmp,tmp2=0;
- int partition,count=0;
- Scanner s=new Scanner(System.in);
- System.out.println("Enter a number and a digit: ");
- num=s.nextInt();
- digit=s.nextInt();
- tmp=num;
- k= (int) Math.pow(10,digit);
- while(tmp>0){
- partition = tmp % k;
- while(partition>0){
- tmp2*=10;
- tmp2+=partition%10;
- count++;
- partition/=10;
- }
- newNum += location * tmp2;
- location *= Math.pow(10,count);
- tmp2=0;
- count=0;
- tmp /= k;
- }
- System.out.println(newNum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement