我有這個我爲課程創建的java代碼。我已經嘗試並繼續失敗實施一個突破聲明。試圖設置break語句
有人能指出我正確的方向嗎?
import java.util.Scanner;
public class gradeAverage {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int input1;
int input2;
int input3;
//Calculate
int studentAvg;
//Prompt for first user input or break if input = q
System.out.print("Enter first student grade or q to quit: ");
if {
(input1=input.nextInt() = q)
break;
else
input1=input.nextInt() =;
}
//Prompt for second user input or break if input = q
System.out.print("Enter second student grade or q to quit: ");
input2=input.nextInt();
//Prompt for third user input or break if input = q
System.out.print("Enter third student grade or q to quit: ");
input3=input.nextInt();
studentAvg=(input1+input2+input3)/3;
System.out.printf("The Student's grade average is %d\n" , studentAvg);
}
}
請勿將變量遠離真正需要使用它的地方。 'int input2 = input.nextInt();''int input3 = input.nextInt();''int studentAvg =(input1 + input2 + input3)/ 3;''''代碼找出這個特定的'studentAvg'是int/lond/float還是double ... – dantuch 2013-03-18 02:09:00