How to quit the program in Java SE??

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

Hello Dr Clap
Thank you for your reply. I really appreciate it.
It's just that I have only recently started learning how to use Java, I am still building on my knowledge.
My program works, however once I get to quitting the program by pressing 'q', the following comes up, rather than 'Press any key to continue' which is the ideal.
"Exception in thread "main" java.lang.NumberFormatException: For input string: "q........"
I sent you the complete program, what details are you talking about?
I am not quite sure where I went wrong. So I would really appreciate it if you could help me.
Thank you
import java.util.Scanner;
public class Week77
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'):");
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
//else if the user does not enter the mark
                    System.exit(0);
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<40)
grade ='F';
return grade;
}

Similar Messages

  • So I downloaded the wrong Airplane Mode program for my operating system and I now have AppleScript Error message.  It will not allow me to quit the program.  Also, once that happens how do I remove the program from the computer?

    So I downloaded the wrong Airplane Mode program for my operating system and I now have AppleScript Error message.  It will not allow me to quit the program.  Also, once that happens how do I remove the program from the computer?

    What Airplane Mode program? To stop a running program launch Activity Monitor (in utilities folder) and quit the program from there. To remove the program drag it to the trash or better use the uninstaller that should have come with it.

  • How do I get firefox to save tabs when I quit the program? This doesn't appear to be available in 4.0

    On previous firefox version, when I quit the program, a prompt would ask me if I wanted to save tabs. That doesn't appear to be happening with 4.0 upgrade. Can I still save and quit?

    One change in Firefox 4 is to by default stop Firefox displaying the warning message, but it can be turned back on by changing some preferences.
    # Type '''about:config''' into the location bar and press enter
    # Accept the warning message that appears, you will be taken to a list of preferences
    # Locate the preference '''browser.tabs.warnOnClose''', if its value is set to '''false''', double-click on it to change its value to '''true'''
    # Repeat this for these 3 preferences '''browser.warnOnQuit''', '''browser.warnOnRestart''' and '''browser.showQuitWarning'''

  • How to use the program called ZSAPLINK to import Function Name

    How to use the program called ZSAPLINK to import Function Name

    Not sure why you posted into this forum?
    Note the header for this forum:
    This forum is dedicated to all other development-related questions which are not directly addressed by other forums. This includes Business Objects SDKs, products, or technologies which do not fall under BusinessObjects Enterprise, BusinessObjects Edge, Crystal Reports Server, or Crystal Reports (for example Desktop Intelligence SDK, Universe Designer SDK, Portal Integration Kits, Java User Function Libraries, and other third party technologies or development languages).
    Ludek

  • I want to close the iMessage window without quitting the program

    Hi,
    I have run into this problem before and I figured it out before but now it is an issue again and I can't change it. When I let a friend borrow my computer, I logged out of iMessage and now after relogging in, I find that my iMessage program quits once I close the window. This makes it quite difficult if I am running a full screen app and it takes me out of it as soon as I get a message. I don't want to have iMessage on "offline" and this box is unchecked when I quit but it still puts me on "offline". How can I remedy the situation by being able to close the window but not quit the program itself? I just want the notifications on the top but not the whole window to open on me during work or class. Please help

    HI,
    It should, and I repeat should, close the Window Only if you use the red blob to close the window.
    The Messages Window (See Window Menu > Messages CMD + 0) should come back into view using the Window Menu or the keystrokes.
    I tend to run Messages with my Buddy list showing.
    I have used the red Button to "Hide" all of these.
    The red button on the Messages window did not close/Quit the app for me.
    Having said that you seem to be describing different behaviour.
    I rechecked by logging out all my Buddy lists so that the Messages window would be the only window on view.
    It still does not quit the app when I use the Red Button.
    The indicator under the icon in the Dock remains in place.
    I went one stage further and logged the iMessages Account Off Line as well and still the Red Button did not Quit the app.
    IN the Finder > Go Menu > Go to Folder type in ~/Library/Preferences in the Dialogue box that appears.
    Find com.apple.ichat.plist  (this holds the Window locations and actions).
    Drag it to the Trash
    Restart Messages.
    The will recreate the .plist
    You may need to change some settings in the Preferences if you are not using defaults (Font, Colour of Balloon etc)
    10:34 PM      Wednesday; January 16, 2013
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
      iMac 2.5Ghz 5i 2011 (Mountain Lion 10.8.2)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • How to run native program with Java program?

    Hello
    I've got following problem. I'd like to write file browser which would work for Linux and
    Windows. Most of this program would be independent of the system but running programs not. How to run Linux program from Java program (or applet) and how to do it in Windows?.
    Cheers

    Try this:
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec("ls -l");
    InputStream stream = proc.getInputStream();
    InputStreamReader isr = new InputStreamReader(stream);
    BufferedReader br = new BufferedReader(isr);
    String line = null;
    while ( (line = br.readLine()) != null) .....
    "if the program you launch produces output or expects input, ensure that you process the input and output streams" (http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html)

  • I want "close window" to quit the program...

    I'm setting up a Mac for my daughter, and I'd like to have "close window" (clicking the red x circle) actually quit the program. Some software on my mac does this, but most needs to be told to quit. My specific request concerns PhotoBooth and iChat. She likes both programs, but both cannot run at the same time because the camera is in use. I'm trying to teach her how to quit programs, but she has just turned 7 and she spends half her time on Windows. What can I do to accomplish this?

    How about this idea?
    Teach her the basic concept of the Mac OS: look at the menu bar.
    In fact, all she really has to do is look at the first words in the upper left corner, and they are even bolded to stand out from the rest of the words on the menu bar. Consider: it's a lot like a book. You go from left to right, top to bottom. In this case, the top left has the most important info: the name of the application. Knowing what application you're in is the first step in knowing what you are doing.
    That's all there is to it: look at the menu bar. Even better, the menu bar is the source of most anything you'd ever want to do with an application.
    Trust me, it's not her being 7 that is the issue. My parents are much older than 7 and they have similar experiences with not knowing how to quit applications. The main difference with my parents and your daughter is my parents don't even have any experience with MS Windows, not much anyways. So, they have to also learn the concept of applications: opened or closed, what can be done with an application, exchanging data between applications, etc.
    Being rather new to computers isn't really based on age, but instead experience. Learning to look at the menu bar is kind of like checking the headline of a newspaper article, or the track number on a CD player, or the times for cable TV programs when viewing the schedule channel. However, relating these other experiences to a computer isn't necessary, I'm just pointing out how the menu bar isn't really a foreign experience even if it may be new to someone.
    Try not to limit her just because you don't believe in her ability to eventually learn something new. I overwhelmed my parents with too much info, and so now I"m repeating a lot of what I said before because they weren't in a situation to make use of what I told them. Perhaps like me, you haven't simplified the approach. Try not to explain everything that can be done from the menu bar. Just the basics of the application name and using the Quit option in its menu is fine for now. She can explore the other menus on her own, or you can refer to a menu item when she asks how to do something else.
    As to keyboard shortcuts, they are in the menus, so she can learn them later anytime she wants, as long as you properly introduce her to basic concept: look at the menu bar. She'll go far with knowledge of that concept.
    MacBook 2.0 GHz Intel Core Duo   Mac OS X (10.4.7)   512 MB RAM

  • How to prevent the program not to skip the process when exception is genera

    Hi, friends.
    How to prevent the program not to skip the process when exception is generated?
    For example, I am doing a process for 100 records. If the 15th record causes a Java Exception, I want to be able to skip it and continue processing the remaining 85 records.
    How it is possible with Java Exception handling? Any sample code?
    Thanks,
    Jaykishan

    [http://java.sun.com/docs/books/tutorial/essential/exceptions/]
    while (there are more lines) {
      try {
        process the next line
      catch (...) {
        log the error
    }[http://java.sun.com/docs/books/tutorial/essential/exceptions/]
    You'll want to be careful about which exceptions you catch though. For instance, if there's an unchecked exception, like NullPointerException, it's a sign of a bug in your code. Continuing to process as if that bug weren't there is often a worse approach than just failing. In this particular case, however, as long as you log the exception and then followup by fixing the bug that caused it, it may be acceptable to continue trying to process the rest of the file, even if some lines bring out a bug in your code.

  • Netbeans startup locatoin and short key to quit the program

    Hi,
    The OS: Solaris 8, and i use Exeed onDemand to connect and start up the netbeans 5.5. The thing is that when it start up, the ide is placed on place on the screen that i cant se any "file..edit.. " tool bar (main toolbar). I cant either quit the program because i cant se the buttons to quit.
    So my question is:
    How do i start netbeans so that i can change the place where it start? Can i specify any arg on start up like userdir?
    What is the short key cmd to quit the netbeans?
    in advance thank u for taking time to help =)

    Have u tried alt-space? This might display the system menu from where you can select 'x' for maxnimzie which would should the entire ide, or select 'size' and size the ide. (The ide would remember the new size and start next time at that size and location).

  • How to clear the screen in java?

    Hi,
    How to clear the screen in java without using any loops?
    Thanks

    Just paint with your background color to let the old paintings vanish.

  • How to view the program panel in full screen mode?

    I know how to make the program panel full screen using the "~" key, but I would like to view my work completely without borders. Similar to using Quicktime or Windows media player. I can't imagine that this feature doesn't exist. Any help would be greatly appreciated.

    This feature is new to CS6. Hit ctrl+` (ctrl+grave).

  • HT4550 Lately I find that there is a change in my Safari program.  I am no longer able to minimize Safari, instead I only have the choice of quitting the program.  What do I need to do to bring back the minimize feature?

    Lately I find that there is a change in my Safari program.  I am no longer able to select "minimize" when I want to save the present page for a later time.  Instead, I can only quit the program to get out of it.  Please tell me what I need to do to get the minimize feature back.  Thank you.

    Hi...
    "minimize" when I want to save the present page for a later time
    Minimize reduces the size of the window. It doesn't save the page.
    Click the Reading List icon just to the left of the Bookmarks icon left side of the Safari toolbar then drag the url from the Safari Address Bar to the Reading List.
    You can access saved pages from there.
    edited by:  cs

  • How to find the program name of the smart form?

    How to find the program name of the smart form if output type is not known?
    thanks in advance...

    How to find the program name of the smart form if output type is not known?
    thanks in advance...
    T-code SE16
    Enter table name: TNAPR  -> Press enter key
    Enter smartform name in input field(SFORM):  Z_your_smartform_name
    Execute
    you can find  program name under the column PGNAM/Program name.
    Regards
    sudheer

  • How to find the program name of the created sap query ?

    how to find the program name of the created sap query ?

    Hi avinash,
    Try in this way..
    Go to SE16 and then go to table TSTC.
    in that give program name as <b>*followed by your query name</b>
    (for example *TESTQUERY)
    and run , that will give progname======queryname.
    this way you can find program name.
    vijay

  • My itunes continues to play very faintly after I quit the program, what could cause this?

    My itunes continues to play very faintly after I quit the program.  I actually though I was going crazy but it does continue to play after the program has been shut down.  Very, very low volume though.  I can't pause it or turn it up or down.  I do us imatch.  Please Help!!!!

    Do you have backups of all the data on the startup drive? If not, do nothing else until you've backed up that data, if you still can.

Maybe you are looking for