(((急!!!!)))JAVA加減乘除 我無法編譯@@
import java.util.Scanner; // program use class Scanner
public class oop
{
// main method begins execution of Java application
public static void main(String[] args)
{
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
int number1; // first number to arithmetic
int number2; // second number to arithmetic
char operation; // the arithmetic operator
double consequence; // the consequence of the expression
System.out.print( "Enter the integer: " ); // prompt
number1 = input.nextInt(); // read the number from user
System.out.print( "Enter the integer: " ); // prompt
number2 = input.nextInt(); // read the number from user
System.out.printf( "Enter the arithmetic operator: " ); // prompt
operation=(char)System.in.read();
switch ( operation )
{
case '+': // grade was between 90
consequence = number1 + number2;
break;
case '-': // and 100
consequence = number1 - number2; // increment aCount
break; // necessary to exit switch
case '*': // grade was between 80 and 89
consequence = number1 * number2; // increment bCount
break; // exit switch
case '/': // grade was between 70 and 79
consequence = number1 / number2; // increment cCount
break; // exit switch
default:
break;
} // end switch
System.out.printf( "Your expression is \"%s %s %s\".\nAnd your consequence is %s.",
number1,operation,number2,consequence );
}
}
請幫我找錯誤在哪!!!!!!!
謝謝
1 個解答
- 1 0 年前最佳解答
import java.util.Scanner; // program use class Scanner
import java.io.*; //<-載入IO套件因為主程式需要throws IOException(因為有輸入)
public class OOP {
// main method begins execution of Java application
public static void main(String[] args)throws IOException {
// create Scanner to obtain input from command window
Scanner input = new Scanner( System.in );
int number1; // first number to arithmetic
int number2; // second number to arithmetic
char operation; // the arithmetic operator
double consequence=0; // the consequence of the expression 這邊要給初始值 我給0
System.out.print( "Enter the integer: " ); // prompt
number1 = input.nextInt(); // read the number from user
System.out.print( "Enter the integer: " ); // prompt
number2 = input.nextInt(); // read the number from user
System.out.printf( "Enter the arithmetic operator: " ); // prompt
operation=(char)System.in.read();
switch ( operation ) {
case '+': // grade was between 90
consequence = number1 + number2;
break;
case '-': // and 100
consequence = number1 - number2; // increment aCount
break; // necessary to exit switch
case '*': // grade was between 80 and 89
consequence = number1 * number2; // increment bCount
break; // exit switch
case '/': // grade was between 70 and 79
consequence = number1 / number2; // increment cCount
break; // exit switch
default:
break;
} // end switch
System.out.printf( "Your expression is \"%s %s %s\".\nAnd your consequence is %s.",number1,operation,number2,consequence );
}
}
就以上這兩個問題而已 不懂在發問
參考資料: Myself