私はこれまでにプログラミングクラスを受講したことはありません。そのため、私はこのすべてを非常に新しくしており、私の答えを書面で表示させるために少しでも挑戦しています。たとえば、ユーザーが数字2と5と*を入力した場合、答えは5を2倍したものが10で表示されるはずです。 ここに私のプログラムがあります: import java.util.Scanner;私の電卓プロジェクトの答えを答えとして表示する方法がわからないのですか?
public class CalculatorProjectCH
{//begin class
public static void main(String[] args)
{//begin main
//このプログラムでは、0-9の2桁の数字を入力し、操作方法を入力するように求められます。
System.out.println("This program will act as a simple calculator. ");
System.out.println("It will ask you to enter two numbers from 0-9 and a method of operation "
+"(+, -, *, /, ^.) ");
//Declare variables input1, input2, result1, result2, result3, result4, and result5, as doubles.
double input1, input2, result1, result2, result3, result4, result5;
String text;
//Create scanner object to allow for input
Scanner input = new Scanner (System.in);
//Ask the user to enter the first number
System.out.print("\nEnter your first number: ");
input1 = input. nextDouble();
//Ask the user to enter the operation
System.out.println("Please enter the operation you would like to execute: ");
text = input.next();
//Ask the user to enter the second number
System.out.println("Enter your second number: ");
input2 = input.nextDouble();
result1= input1+input2;
result2= input1-input2;
result3= input1*input2;
result4= input1/input2;
result5= Math.pow(input1,input2);
switch (text)
{
case "+" :
System.out.println(result1);
break;
case "-" :
System.out.println(result2);
break;
case "*" :
System.out.println(result3);
break;
case "/" :
System.out.println(result4);
break;
case "^" :
System.out.println(result5);
break;
//If the user did not enter a valid method of operation
default :
System.out.println("Your operation was not recognized.");
}
}//end main
}//end class
あなたは、あなたの代わりに10の "10" を表示したいわけ? – Sweeper
いいえ私はそれが2で5倍されたとして表示する必要があることを意味します。 –