Problem using Input stream reader - unable to read values in variables

Hi,
I have a program that need to input an access code. If the code is correct a message appears "Valid access code". Till this part, the codes works fine.
The problem is here:
If not correct a prompt is displayed asking the user whether he want to input another code. Whether Y/N, the program always ask for the input. Can anyone tell me what's the problem in the code??
import     java.io.*;
public     class     testwhile
     public static void main(String args[])
          //initialisation for input
          InputStreamReader stdin =
                    new InputStreamReader(System.in);
          BufferedReader console =
                    new BufferedReader(stdin);
          //array to store copier access codes and associated max number of copies
          int[][] arr_copier = new int[3][2];
          int     i = 0;
          String c_code;
          int p_validrow; //use to input copier access code
          String     p_reply,p_tryagain, p_found;
          int copier_code;
          //assigning values to array
          arr_copier[0][0] = 450101;
          arr_copier[1][0] = 450202;
          arr_copier[2][0] = 430303;
          arr_copier[0][1] = 500;
          arr_copier[1][1] = 2000;
          arr_copier[2][1] = 100;
          p_tryagain ="N";
          p_found = "N";
          p_validrow = 0;
          c_code = "0";
          try
          do
                    System.out.print("Input code: ");
                    c_code = console.readLine();
                    copier_code = Integer.parseInt(c_code);
                    for (int r=0;r<=2;r++)
                         // System.out.println(r + " = " + arr_copier[r][0]);
                         if (copier_code == arr_copier[r][0])
                              System.out.println("Value found");
                              p_found = "Y";
                              p_validrow = r;
                              break; // to know row number so as to pick the number of copies for the selected access code
                         else
                              System.out.println("NOT found");
                              p_found = "N";
                    if (p_found == "N")
                         System.out.println("Invalid access code");
                         System.out.print("Do you want to try another code?");
                         p_tryagain = console.readLine();
                    else     
                         System.out.println("VALID access code");
                         p_tryagain = "N";
               p_tryagain = p_tryagain;
               System.out.println("try again" + p_tryagain);
          while (p_tryagain != "N");
          catch(IOException ioex)
                    System.out.println("Error Exception" + ioex);
}

Never compare Strings using Object equality or inequality ("==" resp. "!=").
Use [url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#equals(java.lang.Object)]String#equals (or [url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#indexOf(java.lang.String)]String#indexOf or [url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#matches(java.lang.String)]String#matches).
Please use code tags when posting code. This means wrapping your text between [code[/b]][[/b]code] tags. See the [url http://forum.java.sun.com/help.jspa?sec=formatting]Formatting tips.

Similar Messages

  • The new ibook app and ibook update is designed for iPhone 5 operating system.   When my iPhone4 recently updated the ibook app, it created many problems using the ibook to download and read my books.    Can I get the previous ibook app back on my phone.

    The new ibook app and ibook update is designed for iPhone 5 operating system.   When my iPhone4 recently updated the ibook app, it created many problems using the ibook to download and read my books.    Can I get the previous ibook app back on my phone.

    Check your trash can on the desktop. The old version is automatically moved to the trashcan. You should be able to move it from the trashcan back to the Apps folder within the iTunes folder. The update that was pushed out was for iBooks to work with iOS 7 not iPhone 5. iOS 7 was released today.

  • Problems using event structure to write new parameter values to VISA

    Attachments:
    FMA_event_2.vi ‏28 KB
    FMA_event_2.vi ‏28 KB

    It seems I'm also having trouble using forums..not sure what happened...updated and corrected thread: http://forums.ni.com/t5/LabVIEW/Problems-using-event-structure-to-write-new-parameter-values-to/td-p...

  • I have a problem in using input stream in ftp

    Hi dear members,
    i have a problem. i am using below code to have inputstream of the file. f is directory and osconfigscript[q] is a file, which is already existing.
    InputStream is = new BufferedInputStream(new FileInputStream(new File(f,osconfigscript[q])));
    Later on i am using this input stream to ftp it .
    ftp.setFileType(FTP.BINARY_FILE_TYPE
    ftp.storeFile(osconfigscript[q],is) ;
    But the content i am getting in the ftp server is not same as i have sent.
    though the file name and it's remain same. the content become unreadable. the ftp class that i have used is
    "org.apache.commons.net.ftp.FTPClient".
    what should i do to make my content readable in the ftp server.

    I found the answer myself. Actually i was doing hot deployment in my jboss server (through eclipse jboss plug-in) . This was cause of the error .i have done the cold deployment now it is working.
    Hot deployment is works better in the JDeveloper then in eclipse - jBoss combo.
    no i have not used inputstream stream between its creation and passing it into the ftp method.

  • When I read a pdf document using Safari I'm unable to read more than one page of a file. A padlock icon is locked on the tab. Please help.

    When I read a pdf document using Safari on my IPad  I'm unable to read more than one page of a file. A padlock icon is locked on the tab. Please help.

    Hi snoreaustralia,
    It sounds like you just need to associate the PDF filename extension with Acrobat, rather than Preview. Please see this document from the Microsoft Help for instructions on choosing the default program for opening a particular file type (in your case, PDF): Change which programs Windows uses by default - Windows Help
    Best,
    Sara

  • Create HelpSet using input stream and not URL

    Hi All,
    I looked over the docs and apis and I was not able to find any way to create a HelpSet from an input stream.
    Basically all I have is are input streams to the help files and not URLs, is there a way to initialize the help set with that?
    thanks

    Never compare Strings using Object equality or inequality ("==" resp. "!=").
    Use [url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#equals(java.lang.Object)]String#equals (or [url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#indexOf(java.lang.String)]String#indexOf or [url http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#matches(java.lang.String)]String#matches).
    Please use code tags when posting code. This means wrapping your text between [code[/b]][[/b]code] tags. See the [url http://forum.java.sun.com/help.jspa?sec=formatting]Formatting tips.

  • Problem using Cipher*Stream and Properties

    I ran into a tricky problem using CipherInputStream, CipherOutputStream and Properties. I don't seem to find where I'm doing something wrong here.
    I have something like this:
    encCipher; // and already initiated ENCRYPTION Cipher
    FileInputStream fis = new FileInputStream( "textfile.properties" );
    // textfile is an unencrypted text-file containing:
    // prop1=valueprop1
    // prop2=valueprop2
    // prop3=valueprop3
    Properties props = new Properties();
    props.load( fis );
    FileOutputStream fos = new FileOutputStream( "enctextfile.properties" );
    CipherOutputStream cos = new CipherOutputStream( fos, encCipher );
    props.store( cos );Up until here, no problems right? I get the contents from the source text-file, and then write with to the CipherOutputStream, which gives me an encrypted version of the original file.
    Then: (assume decCipher is an already initiated DECRYPTION Cipher)
    FileInputStream fis = new FileInputStream( "enctextfile.properties" );
    CipherInputStream cis = new CipherInputStream( fis, decCipher);
    Properties props = new Properties();
    props.load( cis );
    props.list( System.out ); // this line should produce the exact same contents as the original source file right?But the output has one property less, as if in some part of this process, data has been lost. But where? Am I missing something?
    Thanks in advance for any hints,
    Chris

    Yes. Just now I realize I must close it for all the
    buffer to be written out to the file.:-) My crystal ball is working well today!

  • HT201077 problems using photo stream on mac

    Have set up photo stream and iColud correctly but when I receive email from friends to join photo stream the link sends me directly to the "get started" page. What to do?

    What system version are you running?  For shared Photo Streams you need to be running 10.8.2 or later.  The following is from iCloud: Photo Stream FAQ
    What do I need to use Photo Stream?
    To use Photo Stream, including Shared Photo Streams, you need an iCloud account, compatible devices, and up-to-date software:
    iPhone, iPad, or iPod touch with iOS 6.0 or later
    Mac with OS X Mountain Lion v10.8.2 or later and iPhoto 9.4 or Aperture 3.4 or later
    You can still use Photo Stream without Shared Photo Streams if your devices meet these requirements:
    iPhone, iPad, or iPod touch with iOS 5.1 or later
    Mac with OS X Lion v10.7.5 or later and iPhoto 9.2.2 or Aperture 3.2.3 or later
    OT

  • Problems using java.xml.xpath - How to get values from DTMNodeList?

    Sorry for the waffle in the subject title, but I was unsure what to call it. I hope this thread is in the correct forum.
    I'm having problems using xpath to parse some data from an XML file. I am able to create an expression which obtains the elements I wish to retreive, but I'm unsure on how to go about getting their values. So far I have..
    public int getTerms(int PMID)
              String uri = "http://www.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id="
                           + PMID + "&retmode=xml";
              // Create an XPath object with the XPathFactory class
              XPathFactory factory = XPathFactory.newInstance();
              XPath xPath = factory.newXPath();
              // Define an InputSource for the XML article
              InputSource inputSource = new InputSource(uri);
              // Create the expression
              String expression = "/PubmedArticleSet/PubmedArticle/MedlineCitation/MeshHeadingList/MeshHeading/DescriptorName";
              // Use this expression to obtain a NodeSet of all the MeSH Headings for the article
              try
                   DTMNodeList nodes = (DTMNodeList) xPath.evaluate(expression,
                         inputSource, XPathConstants.NODESET);
                   int length = nodes.getLength();
                   String[] terms = new String[length];
                   // Test mesh terms are being stored.
                    *for (int i=0; i<length; i++)*
    *                    System.out.println(i + ": " + nodes.item(i).getNodeValue());*
                                                    return nodes.getLength();
              catch (XPathExpressionException e2)
              { System.out.println("Article with PMID " + PMID + " has no associated MeSH terms");}
              // return a default
              return 0;
         } The part in bold is the problematic code. I wish to retreive the values of each of the nodes I have taken into my DTMNodeList using a for loop to iterate through each node, and use the getNodeValue() method from the Node class which should return a string. However, the values I retreive are NULL. In the test document I use, the elements do have values.
    Here is a snippet of the XML file I am reading in:
    <MeshHeadingList>
      <MeshHeading>
      <DescriptorName MajorTopicYN="N">Binding Sites</DescriptorName>
      </MeshHeading>
    - <MeshHeading>
      <DescriptorName MajorTopicYN="N">Chromatium</DescriptorName>
      <QualifierName MajorTopicYN="Y">enzymology</QualifierName>
      </MeshHeading>
    - <MeshHeading>
      <DescriptorName MajorTopicYN="Y">Cytochrome c Group</DescriptorName>
      </MeshHeading>
    - <MeshHeading>
      <DescriptorName MajorTopicYN="N">Electron Spin Resonance Spectroscopy</DescriptorName>
      </MeshHeading>
    - <MeshHeading>
      <DescriptorName MajorTopicYN="N">Flavins</DescriptorName>
      </MeshHeading>
    - <MeshHeading>
      <DescriptorName MajorTopicYN="N">Heme</DescriptorName>
      </MeshHeading>
    - <MeshHeading>
      <DescriptorName MajorTopicYN="N">Hydrogen-Ion Concentration</DescriptorName>
      </MeshHeading>
    - <MeshHeading>
      <DescriptorName MajorTopicYN="N">Iron</DescriptorName>
      <QualifierName MajorTopicYN="N">analysis</QualifierName>
      </MeshHeading>
    - <MeshHeading>
      <DescriptorName MajorTopicYN="N">Magnetics</DescriptorName>
      </MeshHeading>
    - <MeshHeading>
      <DescriptorName MajorTopicYN="N">Oxidation-Reduction</DescriptorName>
      </MeshHeading>
    - <MeshHeading>
      <DescriptorName MajorTopicYN="N">Protein Binding</DescriptorName>
      </MeshHeading>
    - <MeshHeading>
      <DescriptorName MajorTopicYN="N">Protein Conformation</DescriptorName>
      </MeshHeading>
    - <MeshHeading>
      <DescriptorName MajorTopicYN="N">Temperature</DescriptorName>
      </MeshHeading>
      </MeshHeadingList>Any help would be appreciated.. thanks :-)

    Answered my own question....
    The element value is actually the child of the node I am current at, so instead of doing:
    i + ": " + nodes.item(i).getNodeValue()); I should have really done:
    i + ": " + nodes.item(i).getChildNode().getNodeValue());

  • Hi problem in Input stream - Junk character

    Hi
    We are developing a application in which a java servlet reads a request from a xls file
    The request is sent from a macro written in excel file.
    The request sends a xml file content in byte form.
    This we read in the servlet as a datainputstream.
    While printing we encounter a problem
    After every valid character a junk character is also getting printed(it is in form of a square).
    example
    < (junk) x (junk) m (junk).............
    Can somebody help how to solve this
    Thanks
    Ottran
    Message was edited by:
    Ottran

    Sounds to me like the XML is being encoded in some version of UTF-16, but you're ignoring that and acting as if it's in some single-byte encoding. I would certainly question the use of DataInputStream to read it, as that class has assumptions built into it which you could easily misuse.
    And "printing" is a term that could use a whole lot of clarification, especially in the context of a Web application.

  • Strange problem creating input stream in Java 1.4

    I need to create an InputStream from a file that is in the same directory as the class App. But this code (in App)
    File file = new File(App.class.getResource("filename").getFile());
    InputStream is = new InputStream(file);
    throws this exception:
    java.io.FileNotFoundException: c:\my%20programs\filename (The system can not find the file specified)
    The exception is only thrown in jdk1.4. In jdk1.3 everything works perfectly(as it should). What seems to happen is that the space in the directory name "my programs" is turned into "%20". This problem doesn't arise if directory names in the file path don't contain spaces or if I use the File(String) constructor.
    Can someone, please, explain this anomaly or, at least, how I can get an InputStream in this situation without using the Class.getResource().getFile() call.

    Did you try
    InputStream is = new InputStream(file.getCanonicalPath ());
    instead of
    InputStream is = new InputStream(file);
    It might work.

  • Error message reads: Unable to read file. It appears to have been corrupted

    Any advice on what to try after receiving the error message above? What more can I tell you? Desperate!

    I'm guessing you had updated to at least 4.1 or maybe 4.5 - a project saved from 4.5 DEFINITELY would cause this error when opened in rev 4.
    Update your install and you should be good. Might have been what was wrong with your other project.
    Patrick

  • Reading data from input stream on unix

    I have a program that reads data from input stream from the socket. If the data is over 1500 bytes it is sent in multiple TCP packets. Whats weird is, if I run the program in windows environment it waits till it receives all the packets but when I run the same program in unix environment it only reads the first packet and go further without waiting for all the TCP packets!!
    The line that reads from input stream is
    datalen = inStr.read(byteBuffer);is there anyway I can make it wait till it receives all the packets on unix system? I do not understand why it works fine for windows in this case but not for unix.
    I'll appreciate any help..
    Thanks

    Try using a DataInputStream with the readfully() method.

  • Reading input stream over the tcp socket in unix

    I have a program that reads data from input stream from the socket. If the data is over 1500 bytes it is sent in multiple TCP packets. Whats weird is, if I run the program in windows environment it waits till it receives all the packets but when I run the same program in unix environment it only reads the first packet and go further without waiting for all the TCP packets!!
    The line that reads from input stream is
    datalen = inStr.read(byteBuffer);is there anyway I can make it wait till it receives all the packets on unix system? I do not understand why it works fine for windows in this case but not for unix.
    I'll appreciate any help..
    Thanks

    When the network is busy there can be any amount of dleay between packets. If this is ever 100 ms , then this will break.
    If you send more than one packet per 100 ms you will get two packets at once which will look like one longer packet. Unless you check for this the second packet may get ignored.
    The safe way is to send the packet size before sending the packet. Then on the client read the packet to the correct length. Otherwise you will have a program which just happens to work rather than one which will always work.

  • TS3899 Unable to read emails on iPhone.

    I have internet access and everything works fine on my iPhone except that when I click on the mail icon, after a few seconds it turns blank and takes me back to the home page on my iPhone. I turned the power off twice and the problem continues and I am unable to read any of my emails on my iPhone.

    Hi cblira!
    Here is an article with some tips about troubleshooting the mail app:
    iOS: Troubleshooting Mail
    http://support.apple.com/kb/ts3899
    If the steps in that article do not resolve the issue, you may need to restore your device:
    Use iTunes to restore your iOS device to factory settings
    http://support.apple.com/kb/ht1414
    Take care, and thanks for visiting the Apple Support Communities.
    Cheers,
    Braden

Maybe you are looking for