Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner; // Needed for accepting input
- import java.text.*;
- import java.lang.Math.*;
- public class ProjectOneAndreD
- {
- public static void main(String[] args)
- {
- String input1;
- char coln = ':';
- int val=0, rad=0, check1=0;
- double answer1=0, answer2=0;
- Scanner keyboard = new Scanner(System.in); //creates new scanner class
- do
- {
- System.out.println("****************************************************");
- System.out.println(" This is Project 1. Enjoy! "); //title
- System.out.println("****************************************************\n\n");
- System.out.println("Enter a number, : and then the radix, followed by the Enter key.");
- System.out.println("INPUT EXAMPLE: 160:2 {ENTER} "); //example
- System.out.print("INPUT: "); //prompts user input.
- input1 = keyboard.nextLine(); //assigns input to string input1
- check1=input1.indexOf(coln);
- if(check1==-1)
- {
- System.out.println("I think you forgot the ':'.");
- }
- else
- {
- String numbers [] = input1.split(":"); //if the user enter 1123:2342 this method
- //will
- // return array of String which contains two elements numbers[0] = "1123" and numbers[1]="2342"
- val = Integer.parseInt(numbers[0]); //parses [0] to int and assigns to val
- rad = Integer.parseInt(numbers[1]); //parses [1] to int and assigns to val
- answer1 = ((Math.log(val))/(Math.log(rad))); //mathematically finds first base then
- answer2 = ((Math.log(answer2))/(Math.log(10)));
- System.out.println(val+" base "+rad+" is "+answer2+" base 10.");
- }
- }while(check1==-1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement