Advertisement
taweesoft

Untitled

Sep 3rd, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. //elab-source: NumberBaseConverter.java
  2. import java.util.Scanner;
  3. public class NumberBaseConverter {
  4.     public static void main(String [] args) {
  5.         Scanner input = new Scanner(System.in);
  6.         int ans = 0,counter = 0,count = 0;
  7.         System.out.print("Input B = ");
  8.         int b = input.nextInt();
  9.         System.out.printf("Input number in base %d : ",b);
  10.         int numInBase = input.nextInt();
  11.         String Base = b+"";
  12.         count = Integer.toString(numInBase).length()-1;
  13.         while (count>=0){
  14.             ans += Math.pow(b,count)*Integer.parseInt(Integer.toString(numInBase).substring(counter, counter+1));
  15.             counter++;
  16.             count--;
  17.         }
  18.         System.out.printf("%d base %d is equal to %d.",numInBase,b,ans);
  19.        
  20.     }
  21.  
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement