Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to quit the program in Java SE??

816784Nov 19 2010 — edited Nov 23 2010
Hi,

The program below runs perfectly fine, however once I get to the stage of quitting it doesn't work.
I would like 'Press any key to continue' to appear once I have pressed q.

______________________________________________________________________________________________________________

import java.util.Scanner;
public class Week7777
{
public static void main(String[] args)
{
int j = 0;
while (j <1)
{
Scanner in = new Scanner(System.in);

System.out.println("Enter the student's mark as a percentage ('q' to quit): ");
String input = in.nextLine();
int inputmark = Integer.parseInt(input);
char g = getGrade(inputmark);


if (inputmark<=100)
{
System.out.println("The student's grade is " + g );
}
else {
System.exit();
}

j--;
}

}
private static char getGrade(int mark)
{
char grade= 0;
if (mark >= 70)
grade = 'A';
else if (mark>= 60)
grade ='B';
else if (mark>= 50)
grade ='C';
else if (mark>= 40)
grade ='D';
else if (mark>= 30)
grade ='F';

return grade;
}
}


______________________________________________________________________________________________________________


Please, can you help me sort out this problem.
Thank you
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 21 2010
Added on Nov 19 2010
13 comments
596 views