0
多くのオプションがある電卓を作ろうとしていますが、入力を継続させようとしているときにいくつか問題があります。 ヘルプ私のコードは以下の通りです。はい高度な電卓のJavaスクリプトの問題
import java.util.*;
class Calculator
{
public static void main(String Args[])
{
int a,func,input;double digit;
System.out.println("THIS IS HOW CALCULATOR WORKS");
do
{
System.out.println("\n\n\n1. Add\n2. Subtract\n3. Divide\n4. Multiply\n5. Square\n6. Square root\n7. Cube\n8. Cube root\n9. Continue\n10. Exit");
System.out.print("\nEnter the serial no. of the operation you would like to perform : ");
Scanner sc=new Scanner(System.in);
a=sc.nextInt();
if(a==1)
{
System.out.println("Enter the number you want to add");
input=sc.nextInt();
System.out.println("Enter number to be added");
func=sc.nextInt();
digit= input+func;
System.out.println("Final Answer:"+digit);
}
if(a==2)
{
System.out.println("Enter the number you want to subtract");
input=sc.nextInt();
System.out.println("Enter number to be subtracted");
func=sc.nextInt();
digit= input-func;
System.out.println("Final Answer:"+digit);
}
if(a==3)
{
System.out.println("Enter the number you want to divide");
input=sc.nextInt();
System.out.println("Enter number to be divide");
func=sc.nextInt();
digit= input/func;
System.out.println("Final Answer:"+digit);
}
if(a==4)
{
System.out.println("Enter the number you want to multiply");
input=sc.nextInt();
System.out.println("Enter number to be multiplied");
func=sc.nextInt();
digit= input*func;
System.out.println("Final Answer:"+digit);
}
if(a==5)
{
System.out.println("Enter the number you want to square");
input=sc.nextInt();
digit= Math.pow(input,2);
System.out.println("Final Answer:"+digit);
}
if(a==6)
{
System.out.println("Enter the number you want to square root");
input=sc.nextInt();
digit=Math.sqrt(input);
System.out.println("Final Answer:"+digit);
}
if(a==7)
{
System.out.println("Enter the number you want to cube");
input=sc.nextInt();
digit= Math.pow(input,3);
System.out.println("Final Answer:"+digit);
}
if(a==8)
{
System.out.println("Enter the number you want to cube root");
input=sc.nextInt();
digit= Math.cbrt(input);
System.out.println("Final Answer:"+digit);
}
if(a==9)
{
System.out.println("\n\n\n1. Add\n2. Subtract\n3. Divide\n4. Multiply\n5. Square\n6. Square root\n7. Cube\n8. Cube root\n9. Exit");
System.out.print("\nEnter the serial no. of the operation you would like to perform : ");
int double digit;
int a=sc.nextInt();
if(a==1)
{
System.out.println("Enter the number you want to add");
input=sc.nextInt();
System.out.println("Enter number to be added");
func=sc.nextInt();
digit= input+func;
System.out.println("Final Answer:"+digit);
}
if(a==2)
{
System.out.println("Enter number to be subtracted");
func=sc.nextInt();
digit= input-func;
System.out.println("Final Answer:"+digit);
}
if(a==3)
{
System.out.println("Enter number to be divide");
func=sc.nextInt();
digit= input/func;
System.out.println("Final Answer:"+digit);
}
if(a==4)
{
System.out.println("Enter number to be multiplied");
func=sc.nextInt();
digit= input*func;
System.out.println("Final Answer:"+digit);
}
if(a==5)
{
digit= Math.pow(input,2);
System.out.println("Final Answer:"+digit);
}
if(a==6)
{
digit=Math.sqrt(input);
System.out.println("Final Answer:"+digit);
}
if(a==7)
{
digit= Math.pow(input,3);
System.out.println("Final Answer:"+digit);
}
if(a==8)
{
digit= Math.cbrt(input);
System.out.println("Final Answer:"+digit);
}
if(a==9)
{
System.out.println("Thank you for using calculator");
}
}
if(a==10)
{
System.out.println("Thank you for using the calculator");
break;
}
}while(a!=9);
}
}
このコードを読むことはできますか? –