Advertisement
3nriched

Untitled

Sep 10th, 2011
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. import java.util.Scanner;  // Needed for accepting input
  2. import java.text.*;
  3. import java.lang.Math.*;
  4.  public class ProjectOneAndreD
  5.  {
  6.  
  7.    
  8.     public static void main(String[] args)
  9.     {
  10.         String input1;
  11.         char coln = ':';
  12.         int val=0, rad=0, check1=0;
  13.         double answer1=0, answer2=0;
  14.  
  15.        
  16.             Scanner keyboard = new Scanner(System.in);  //creates new scanner class
  17.            
  18.             do
  19.         {
  20.             System.out.println("****************************************************");
  21.             System.out.println("             This is Project 1. Enjoy!              ");     //title
  22.             System.out.println("****************************************************\n\n");
  23.  
  24.             System.out.println("Enter a number, : and then the radix, followed by the Enter key.");
  25.             System.out.println("INPUT EXAMPLE:  160:2   {ENTER} ");     //example
  26.            
  27.             System.out.print("INPUT:  ");               //prompts user input.
  28.             input1 = keyboard.nextLine();       //assigns input to string input1
  29.  
  30.            
  31.             check1=input1.indexOf(coln);
  32.            
  33.             if(check1==-1)
  34.             {
  35.                 System.out.println("I think you forgot the ':'.");
  36.                
  37.             }
  38.             else
  39.             {
  40.                 String numbers [] = input1.split(":"); //if the user enter 1123:2342 this method
  41.  
  42.                 //will
  43.                 // return array of String which contains two elements numbers[0] = "1123" and numbers[1]="2342"
  44.                    
  45.                     val = Integer.parseInt(numbers[0]);   //parses [0] to int and assigns to val
  46.                     rad = Integer.parseInt(numbers[1]);     //parses [1] to int and assigns to val
  47.                     answer1 = ((Math.log(val))/(Math.log(rad)));    //mathematically finds first base then
  48.                     answer2 = ((Math.log(answer2))/(Math.log(10)));
  49.                     System.out.println(val+" base "+rad+" is "+answer2+" base 10.");           
  50.             }
  51.                 }while(check1==-1);
  52.                    
  53.     }
  54.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement