코스에 대해 만든이 자바 코드가 있습니다. 나는 break 문을 구현하려고 시도했지만 실패했다.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;'는 괜찮을 것입니다. 코드는 int/lond/float 또는 double입니다. – dantuch