Asenov

Convert from base-7 to decimal

Mar 17th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class ConvertFromBase7ToDecimal {
  4.     public static void main(String[] args) {
  5.         Scanner input = new Scanner(System.in);
  6.         int n = input.nextInt();
  7.         int fromBase = 7;
  8.         int toBase = 10;
  9.         System.out.println(fromBaseToBase(n, fromBase, toBase));
  10.     }
  11.  
  12.     public static String fromBaseToBase(int number, int fromBase, int toBase){
  13.         String numStr = Integer.toString(number);
  14.         try {
  15.             return Integer.toString(Integer.parseInt(numStr, fromBase), toBase);
  16.         }catch (Exception ex){
  17.             return "Invalid Entry!";
  18.         }
  19.     }
  20. }
Add Comment
Please, Sign In to add comment