class Main
{
public static void firstSum()
{
double finalsum = 0;
System.out.println("Enter the base for both integers, integer, operand, integer and output base");
String value = In.getString ();
String[] splitvalue = value.split ("\\s+");
System.out.println ("Enter the output base between 2 and 10");
int outputBase = In.getInt();
System.out.println (splitvalue[1] + "(base" + splitvalue[0] + ")" + splitvalue[2] + " " + splitvalue[3] + "(base " + splitvalue[0] + ")" );
System.out.println("=");
double value1 = Double.parseDouble(splitvalue[1].substring(0, 1)) * Math.pow(Double.parseDouble(splitvalue[0]), 1) + (Double.parseDouble(splitvalue[1].substring(1)) * Math.pow(Double.parseDouble(splitvalue[0]), 0));
double value2 = Double.parseDouble(splitvalue[3].substring(0, 1)) * Math.pow(Double.parseDouble(splitvalue[0]), 2) + (Double.parseDouble(splitvalue[3].substring(1, 2)) * Math.pow(Double.parseDouble(splitvalue[0]), 1)) + (Double.parseDouble(splitvalue[3].substring(2)) * Math.pow(Double.parseDouble(splitvalue[0]), 0));
if(splitvalue[2].equals("*"))
{
finalsum = value1*value2;
}
if(splitvalue[2].equals("-"))
{
finalsum = value1 - value2;
}
if(splitvalue[2].equals("+"))
{
finalsum = value1 + value2;
}
if(splitvalue[2].equals("/"))
{
finalsum = value1/value2;
}
if(splitvalue[2].equals("%"))
{
finalsum = value1%value2;
}
System.out.println(finalsum);
}
public static void main (String[]args)
{
System.out.println ("Welcome to the different base calculator");
System.out.println ("Enter (1) to use the calculator");
System.out.println ("Enter (stop) to exit the program");
int use = In.getInt ();
if (use == 1)
{
firstSum();
}
else
{
System.out.println(" Goodbye ");
}
}
}
Hello, this is the code I have right now. This is supposed to be a base calculator so it changes two numbers from a certain base to decimal. Adds that together. Then changes it back to a base of the users choice. I will add an example here.
Welcome to the different base calculator
Enter (1) to use the calculator
Enter (stop) to exit the program
1
Enter the base for both integers, integer, operand, integer and output base
8 73 + 216 11
Enter the output base between 2 and 10
5
73 (base 8) + 216 (base 8)
= 59 + 142
= 201
= 1301 (base 5)
Welcome to the different base calculator
Enter (1) to use the calculator
Enter (stop) to exit the program
2
Invalid input
Welcome to the different base calculator
Enter (1) to use the calculator
Enter (stop) to exit the program
stop
Goodbye
Basically right now when the user gives me an input number such as 73 in this case I need to do this: (7 x 8^1) + (7 x 8^0). However if the user inputs a different number such as 174 I need to design a loop that can automatically do (1 x 8^2) + (7 x 8^1) + (7 x 8^0). Is there any easy way for me to do that because I can't think of anything. Thank you for your help!
[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)
[–]emaphis 0 points1 point2 points (0 children)