Problem with entering integer numbers from keyboard

I have written this simple code:
import java.io.*;
public class Simple{
     public static void main(String[] args)throws Exception{
          System.out.println("Enter two integer numbers: ");
          BufferedReader enter=new BufferedReader(new InputStreamReader(System.in));
               int first=Integer.parseInt(enter.readLine());
               int second=Integer.parseInt(enter.readLine());
          System.out.println("Result is: "+(first+second));
and it works fine if I type first number, press Enter, then type
second number and press Enter.
But if I type in one line: 2 3 (with space between) I get run-time error:
Exception in thread "main"...bla...bla at java.lang.Integer.parseInt(Integer.java)...
I know that error is coming from Integer.parseInt(string) in my code, but I
don't know how can I avoid it.
In C that is rather simple scanf("%d %d",&first,&second), but in Java it's much more
complicated.
Do you have any suggestions how to solve this problem?

store the user input in a string
use a StringTokenizer st
then
while(st.hasNext())
int first=Integer.parseInt(st.nextToken());
but you should really catch a NumberFormatException
walker

Similar Messages

  • Problem with multiple client numbers from a view

    Hi Gurus,
    I have a problem with a view
    Creates a view with a UNION ALL stmt
    =====================================
    Create view vw_benifits
    as
    SELECT
         Client_num, -- can have multiple values like 200,201,250
         PERNR,     
         OBJPS,     
         ENDDA,     
         BEGDA,
         AEDTM,     
         UNAME,
         COB_MNTH_AMT
    FROM
         STG_SAP_PA9211_TB
    UNION ALL
    SELECT
         null, -- no client number for legacy data
         PERNR,     
         OBJPS,     
         ENDDA,     
         BEGDA,
         AEDTM,     
         UNAME,
    COB_MNTH_AMT
    from
         LEG_STG_SAP_PA9211_TB;
    ==============================
    The second table contains legacy data (LEG_STG_SAP_PA9211_TB). The first table now contains multiple client data (ie the client_num can be 201,202,250 like that.
    Now if the users qery the view they will only get that clients data.
    eg selet * from vw_benifits where client_num=250 results only client 250 data. But I want to add the legacy data also with that.
    I don't want to propose
    selet * from vw_benifits where client_num in (250,NULL) since the users will be confused.
    Is there any other way to do this . my requirement is like
    If they query
    select * from vw_benifits where client_num=250, the data should include all the records satisfying client=250 + the records from the legacy data. The view need to be created like that.
    Appreciate your help
    Deepak

    Hi Thanks for the suggestion.
    But I am not sure this may work for me. Here my users may not be able to use that since they don't know Oracle.
    I want to hide that details from them
    They may just issue a statement like this
    select * from vw_benifits where client_num =250
    Or
    select * from vw_benifits where client_num =400 . But both times I need to show them the data from the legacy table.
    Deepak

  • Problem with Enter key on Aluminum Keyboard

    Just upgraded to an Aluminum iMac with the thin keyboard. We have a terminal application that communicates with our mainframe. The application looks for the 0x03 character, along with the NSNumericPadKeyMask flag, to determine that the Enter key was pressed, and then changes the character to a 0x0d (Return). This is because the 0x03 character is recognized as a Break key on the mainframe. However, when using the Aluminum Keyboard, the Enter key goes straight through as a 0x03, meaning the flag is not being set. To make things more interesting, if I use the Keyboard Viewer and click on the Enter key, the flag is set and the 0x0d is sent.
    Is there something else I should be looking for to recognize the Enter key? Perhaps something with the KeyCode? Is there some way to remap the Enter key to emulate the Return?

    I don't think you'll be able to control a Button symbol in the way you desire.  You probably need to create it as a MovieClip so that you can control what frame it is in.
    To utilize the ENTER key to take action, the following should work...
    var keyListener:Object = new Object();
    keyListener.onKeyDown = function() {
        if (Key.isDown(Key.ENTER)) {
             // do your button_mc control here
    Key.addListener(keyListener);

  • Keyboard problems with Enter, delete, backspace, and right/left arrows

    In some applications, such as Yahoo and this message block right now !!, when composing a message, the arrow keys and delete, backspace keys become non responsive. Various ones will work on a random basis.
    I am getting double "carriage returns" also. Maybe this is why in Omegle when I press ENTER, it will not post a chat message; it will bring up a scroll box and for me to post the comment, I have to use the mouse to click ENTER.
    I have changed batteries in my keyboard, uninstalled /reinstalled Firefox. I have checked the above websites in Chrome and other browsers, and there are no problems.
    This has happened before, I don't recall what the solution was or if it just went away.'''
    Affected sites -- at least these
    http://us.mg6.mail.yahoo.com/neo/launch?ncrumb=Fx5R4O7ccqb&.rand=1041364415&nmig=yes#
    http://omegle.com/
    https://support.mozilla.com/en-US/questions/new?product=beta&category=b2&search=Keyboard+problems+with+Enter%2C+delete%2C+backspace%2C+and+right%2Fleft+arrows&showform=1

    PROBLEM SOLVED: http://forum.archlinux-br.org/viewtopic.php?id=1257
    Solution posted on Brazilian Archlinux forum. Credits to user "920608".
    [cache]
    /etc/xorg.conf
    Section "Files"
             #RgbPath "/usr/X11R6/lib/X11/rgb"
    EndSection
    Section "ServerFlags"
               Option "AutoAddDevices" "False"
    EndSection
    C'ya

  • Haven't been able to use pages for a while.  Keep getting following message.  Have tried reinstalling iWork, but no luck.  Same problems with Keynote and Numbers/Users/scottmcdonald/Desktop/Screen Shot 2012-03-14 at 9.39.52 PM.png

    Haven't been able to use pages for a while.  Keep getting following message.  Have tried reinstalling iWork, but no luck.  Same problems with Keynote and Numbers/

    Have you moved Pages from its installed location? Or just dragged a copy to your current system?
    It can't find some of its resources apparently.
    Peter

  • MacBook Pro 15 with Windows 8.1 installed via Boot Camp problem with keys "@" and " " of the keyboard

    Hello,
    I have a MacBook Pro Retina Maverick in 2013 on which I installed Windows via Boot Camp 8.1.
    The installation went well but when I am running Windows 8.1, I have a problem with "@" and "<" keys on the keyboard.
    When I type the "@" key, I get "<"
    When I type the "<" button, I get "@"
    I have reinstall Boot Camp from Windows 8.1 for reinstall the drivers and see if it would solve the problem but it was not the case.
    Someone of you has he encountered the same problem?
    Thank you.

    The language of my Keyboard is French

  • Problems with importing text messages from PC Suit...

    Problems with importing text messages from PC Suit 7.1.18.0 to my Nokia 5800
     I am trying to import a csv file that contains text messages (Note that this file was created using PC Suit 7.1.18.0) to a subfolder that I have created to My Folders but PC Suits only imports the text messages to the Draft folder. Note that initially it shows that the messages are import in the correct folder but after a refresh it shows them in the Draft Folder. Is their any setting that I should change in the PC Suit or the phone? My computer runs on Windows XP Service Pack 3 and the Nokia 5800 was upgraded to the latest firmware v20.0.012
     Thanks for your help

    Most phones only allows importing of draft and archived box for SMS.
    To do a restoring, you need to backup the SMS as a .nbu file using PC Suite and restore later.
    If you got an SD card, you can also do a backup on the SD Card (backup.arc) then restore later (reset and restore: backup.arc and mmc).
    What's the law of the jungle?

  • Cisco ASA 5505 - problem with negotiating IP address from PPPoE

    Hi all,
    I have problem with negotiating IP address from PPPoE. There is following design: ISP providing vDSL ending on VDSL modem in bridge mode. Behind brigde modem is ASA 5505 terminting PPPoE on OUTSIDE. Everything works fine except  negotiating IP address from PPPoE server.
    I have configured ASA 5505 with (ASA Version 9.2(2)4) for PPPoE like this [1.]. But If i try to "show" IP address on OUTSIDE interface a get this [2.], ok strange but let's continue. If list "show vpdn pppinterface id 1"  i get this [3.]. Seems that I got public IP addres what was right, but this IP address was not associated with interface OUTSIDE?
    Well, if I set IP address manually like this [4.] and also set a default route everything works fine but what will happen when ISP change reservation for my IP address or default gateway. 
    I have tried different version of ASA OS like 8.4, 9.1 but without luck. 
    Can anybody help me. Thanks a lot.
    Regards
    Karel
    [1.]
    interface Vlan100
    description >>VLAN pro pripojeni do internetu<<
    nameif OUTSIDE
    security-level 0
    pppoe client vpdn group O2
    ip address pppoe setroute
    vpdn group O2 request dialout pppoe
    vpdn group O2 localname O2
    vpdn group O2 ppp authentication chap
    vpdn username O2 password *****
    interface Ethernet0/0
    description >>uplink O2 vDSL<<
    switchport access vlan 100
    [2.]
    ciscoasa(config-if)# show ip address vlan 100 pppoe
    ciscoasa(config-if)#  0.0.0.0 255.255.255.255 on Interface: OUTSIDE
    ciscoasa(config-if)# show interface vlan 100 detail
    Interface Vlan2 "OUTSIDE", is up, line protocol is up
     Hardware is EtherSVI, BW 100 Mbps, DLY 100 usec
            Description: >>VLAN pro pripojeni do internetu<<
            MAC address f44e.05d0.6c17, MTU 1492
            IP address unassigned
      Traffic Statistics for "OUTSIDE":
            28 packets input, 1307 bytes
            31 packets output, 721 bytes
            0 packets dropped
          1 minute input rate 0 pkts/sec,  3 bytes/sec
          1 minute output rate 0 pkts/sec,  1 bytes/sec
          1 minute drop rate, 0 pkts/sec
          5 minute input rate 0 pkts/sec,  0 bytes/sec
          5 minute output rate 0 pkts/sec,  0 bytes/sec
          5 minute drop rate, 0 pkts/sec
      Control Point Interface States:
            Interface number is 15
            Interface config status is active
            Interface state is active
    [3.]
    ciscoasa(config-if)# show vpdn pppinterface id 1
    PPP virtual interface id = 1
    PPP authentication protocol is CHAP
    Server ip address is 88.103.200.41
    Our ip address is 85.71.188.158
    Transmitted Pkts: 20, Received Pkts: 16, Error Pkts: 0
    MPPE key strength is None
      MPPE_Encrypt_Pkts: 0,  MPPE_Encrypt_Bytes: 0
      MPPE_Decrypt_Pkts: 0,  MPPE_Decrypt_Bytes: 0
      Rcvd_Out_Of_Seq_MPPE_Pkts: 0
    ciscoasa(config-if)# show vpdn session state
    %No active L2TP tunnels
    %No active PPTP tunnels
    PPPoE Session Information (Total tunnels=1 sessions=1)
    SessID TunID Intf     State       Last Chg
    22298      2 OUTSIDE  SESSION_UP  561 secs
    [4.]
    interface Vlan100
     description >>VLAN pro pripojeni do internetu<<
     nameif OUTSIDE
     security-level 0
     pppoe client vpdn group O2
     ip address 85.71.188.158 255.255.255.255 pppoe setroute
     route OUTSIDE 0.0.0.0 0.0.0.0 88.103.200.41 1

    You're right that the ACL should not affect otherwise allowed communications to the interface address.
    Try disabling the ip audit feature on your outside interface.
    no ip audit interface OUTSIDE AP_OUTSIDE_INFO
    no ip audit interface OUTSIDE AP_OUTSIDE_ATTACK

  • After update 8.1.2 i had problem with sync my content from ITunes with IPod

    After update 8.1.2 i had problem with sync my content from ITunes with IPod. It stucks on moment when its waiting for implementing changes (step 5 of 5) Hours and hours i'm waiting but still the same. So i cant use my Ipod at all. I restarted Ipod and delete and download Itunes again. Still stuck in the same moment. Help please. Someone has some problems like that?

    I have an error message saying that "An unknown error occurred (-54)"

  • Problem with pdf display downloaded from application server

    Hi all,
    I have a problem with displaying pdf downloaded from application server (saved in BINARY MODE).
    I am getting the pdf output of adobe form in FPFORMOUTPUT-PDF as rawstring back to my program and then converting that rawstring into binary form using the function module SCMS_BINARY_TO_STRING.
    Now, when I export the data to presentation server directly using cl_gui_frontend_services=>gui_download, the pdf is downloaded properly.
    However, when I save the data to application server file by looping at the internal table obtained from SCMS_XSTRING_TO_BINARY and using TRANSFER, and subsequently downloading the file in "unconverted format" from AL11 to my desktop, I am getting a "blank" pdf file (with the same number of pages as the one downloaded using gui_download).
    I have tried different encodings during download but in those cases i get corrupted pdf message. only the default option of INTIAL value seems to work.
    I am forced to believe that there is a problem in my code which saves the data to app server but I cant find any solution that is logical. Any solution to this would be greatly appreciated.
    Regards,
    Sasi
    Edited by: Sasi Upadrasta on Sep 29, 2010 7:55 PM

    used a program to read the file from appl server and then downloading it to desktop.

  • Hi, I have problem with importing MOV files from SJCAM 4000. MOV files are in supported formats for Adobe Premiere Elements 11. But if I'm importing MOV file, only audio part is imported, video part is not imported. How can I solve this problem?

    Hi, I have problem with importing MOV files from SJCAM 4000. MOV files are in supported formats for Adobe Premiere Elements 11. But if I'm importing MOV file, only audio part is imported, video part is not imported. How can I solve this problem?

    haben
    From looking at the specifications of your camera (SJCam 4000), we know already what video compression your camera is using. It is H.264.
    A H.264.mov file should be supported by Premiere Elements 11. On what computer operating system is your Premiere Elements 11 running?
    Do you have the latest version of QuickTime installed on your computer? And, are you running QuickTime and Premiere Elements 11 from a
    User Account with administrative privileges? Please go to Premiere Elements 11 Publish+Share/Computer/QuickTime to confirm that you find
    presets there for the QuickTime choice there.
    What are the properties of these H.264.mov files - is it 1080p30 (1920 x 1080p30)  or something else? Do you know if this camera is recording with a variable or
    a constant frame rate?
    Please review and consider and then we will decide what next.
    Thank you.
    ATR

  • HT204150 I'm having problems with random contacts disappearing from icloud. I have a saved text from a contact that displays her info but when I look for her in contacts it's missing.

    I'm having problems with random contacts disappearing from icloud. I have a saved text from a contact that displays her info but when I look for her in contacts it's missing.

    It is locked to your sisters carrier.
    She would have to ask her carrier if they unlock iPhones and if she qualifies for this service.

  • The cursor on my iMac freezes, and I cannot do anything unless I unplug the computer. It is NOT a problem with the mouse or the keyboard ... it is internal. How do I fix this??

    The cursor on my iMac (Panther 10.3.9) freezes to where I cannot do anything unless I unplug the computer. It is NOT a problem with the mouse or the keyboard. How do I solve this problem?

    ClassicII wrote:
    Sorry to say but your imac g5 logic board has bad caps. This was a problem apple had and issued a out of warentee fix but that has now expired.
    The cost to get this repaired is more than what you could find another used imac for.
    I would suggest you get some details before you rush to make a diagnosis. You have absolutely no information to base this on. I see you're hitting up on numerous threads all over the place. Quality, meaning several good posts with reliable advice, is much more worthwhile than quantity.

  • Problem with access to SipFactory from jsp-pages in JBoss environment

    Hello!
    I have an installation of the OCMS 10.1.3.3. deployed into a JBoss (jboss-4.0.5.GA) environment. Unfortunately I have a problem with accessing the SipFactory from a jps-page. Encouraged by the "messagesender" example I tried to get an instance of SipFactory from my jsp-page simply by calling:
    SipFactory sipFactory = (SipFactory) application.getAttribute(SipServlet.SIP_FACTORY);
    But unfortunately there seems to be no attribute "SipServlet.SIP_FACTORY" and I only get a null pointer. I have also tried running that code in the orignal messagesender example but it didn't work either. So I wonder if this should definetely work in a JBoss environment or if this might be a known problem. Is there anything that I could check/do regarding this problem? I suppose there must be an oracle module which should take care of making the SipFactory availabe after it is deployed. Perhaps something went wrong during the deployment?!
    Best regards,
    Tim

    Hi
    On JBoss, OCMS does not support converge applications.
    I.e the SipFactory can be retrieved from the servlet context when running on OC4J.
    Instead the SipFactory can be found in JNDI as described in the Developer's Guide:
    "External Access to SIP Servlets
    To enable convergent applications between SIP and HTTP, the OCMS Container allows you to get access to the javax.servlet.sip.SipFactory by looking it up through JNDI. The SIP Factory will be registered under the same name as the display name of your SIP servlet as illustrated in Example 2–12. The <display-name> in the sip.xml in this case must be "My sip app".
    Example 2–12 Accessing the Data for a SIP Session through JNDI
    InitialContext ic = new InitialContext();
    SipFactory sipFactory = (SipFactory)ic.lookup("sip/My sip app");"
    Cheers
    Lucas Persson

  • Problem with downloading individual songs from an already purchased album to iPhone

    Hi All,
    I'm having problems with downloading single songs from the "purchased" list onto my iPhone. I reset my phone and went to redownload my music, however i only want to download certain songs from different albums which in the past i've been able to do by navigating to the purchases section of the itunes app, then opening each album and selecting the cloud like icon by each song i want.
    Having tried this today, i get the list of songs however the all have a "Purchased" next to them which is greyed out and the only way to download anything is to get the whole album. I've not got iTunes match on and can't think of any settings i've changed, can any suggest what i need to do to enable me to just get a selection of songs?

    Actually Michael I know exactly how to delete.. The iPhone would not let me swipe to the left to delete the individual song, so I went to the album view and did it there.. The issue I am having is a bug because it removed 3/4 of the albums availablity off my iPhone.. You post proved no help because it is basic troubleshooting which, if you read my post, I have already done.. I did however figure out how to fix my issue on my own.. Basically I had to remove the album from my iTunes on my computer and upload it again to iTunes Match..

Maybe you are looking for