import java.util.Scanner; public class InputGrades { public static void main(Str
ID: 3772917 • Letter: I
Question
import java.util.Scanner;
public class InputGrades {
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
String courseId,grade;
int hour,studentId;
for(int i=0;i<10;i++)
{
System.out.println("enter student id");
studentId=Integer.parseInt(scan.nextLine());
for(int j=0;j<5;j++)
{
System.out.println("enter courseId");
courseId=scan.nextLine();
System.out.println("enter hours");
hour=Integer.parseInt(scan.nextLine());
System.out.println("enter grade for this course A or B or C or D");
grade=scan.nextLine();
if(grade.equals("A")||grade.equals("B")||grade.equals("C")||grade.equals("D"))
{
continue;
}
else
{
System.out.println("incorrect grade entered");
break;
}
}
}
}
}
How do I get this to not be continuous? I just want to run it two times then end...
Explanation / Answer
import java.util.Scanner;
public class InputGrades
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
String courseId,grade;
int hour,studentId;
for(int i=0;i<2;i++)
{
System.out.println("enter student id");
studentId=Integer.parseInt(scan.nextLine());
for(int j=0;j<1;j++)
{
System.out.println("enter courseId");
courseId=scan.nextLine();
System.out.println("enter hours");
hour=Integer.parseInt(scan.nextLine());
System.out.println("enter grade for this course A or B or C or D");
grade=scan.nextLine();
if(!grade.equals("A")||!grade.equals("B")||!grade.equals("C")||!grade.equals("D"))
{
System.out.println("incorrect grade entered");
break;
}
else
{
continue;
}
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.