System.in.read and System.out.print questions

On the following code, two questions:
1. the output is not what I expected. Why doesn't the System.out.println(i+" "+(char)i); print everytime i press enter a character? It seems to print all at once after everything is entered.
package stars;
import java.io.*;
public class Stars {
  public static void main (String[] args) throws IOException {
    String U="";
    System.out.print("What is your name: ");
    while (true) {
      int i=System.in.read();
      U+=(char)i;
      System.out.println(i+" "+(char)i);
      System.out.flush();
      if (i==10||i==13) break;
    System.out.println("\rHello "+U);
}C:\>java -cp . stars/Stars
What is your name: blah
98 b
108 l
97 a
104 h
13
Hello blah
2. What is the most natural way to check for the press of an enter key? Is there a java attribute or method for the "Enter key" since it is different on unix and ms-dos? Thanks

On the following code, two questions:
1. the output is not what I expected. Why doesn't
the System.out.println(i+" "+(char)i); print
everytime i press enter a character? From:
http://scv.bu.edu/Doc/Java/tutorial/java/nutsandbolts/input.html
================
"The read() method provided by System.in reads a single character and returns either the character that was read or, if there are no more characters to be read, -1.
When a program reads from the standard input stream, the program blocks waiting for you to type something in. The program continues to wait for input until you give it some indication that the input is complete. To indicate to any program that reads from the standard input stream that you have finished entering characters, type the end-of-input character appropriate for your system at the beginning of a new line"
================
In other words, Java can't do what you want to do.
<snip>
>
2. What is the most natural way to check for the
press of an enter key? Is there a java attribute or
method for the "Enter key" since it is different on
unix and ms-dos? Thanks
System.getProperty("line.separator");Jim S.

Similar Messages

  • I cannot update from OS 10.9.4 to 10.9.5. I get a message saying: File couldn't be installed error (513). I have configured my OS so that I have read and write permission followed by system with read and writ permission. Can someone help me? Thanks.

    I cannot update from OS X 10.9.4 t0 10.9.5> Whenever I try I get the following message: File couldn't be installed error (513) and something about not having the proper permission.  Under the Macintosh HD sharing and permissions settings I have customized the settings so that (Me) has read and write permission followed by the system with read and write permission, wheel and everyone have Read permissions.
    I have no problems updating apps such as Adobe CC or iTunes but cannot update the operating system, can someone help me? Thanks.

    1. Restart the computer in safe mode. Certain caches maintained by the system will be rebuilt.
    Safe mode is much slower to start up than normal. The next normal startup may also be somewhat slow.
    When the login screen appears, restart as usual (not in safe mode) and test. There's no need to log in while in safe mode.
    Note: If FileVault is enabled, or if a firmware password is set, or if the startup volume is a software RAID, you can’t start in safe mode. In that case, go to Step 2.
    If there's no change after taking this step, continue.
    2. Back up all data before proceeding.
    Triple-click anywhere in the line below on this page to select it:
    /var/folders
    Right-click or control-click the highlighted line and select
              Services ▹ Reveal in Finder (or just Reveal)
    from the contextual menu.* A folder should open with an item named "folders" selected. Move the selected item to the Trash. You may be prompted for your administrator login password. Restart the computer and empty the Trash.
    *If you don't see the contextual menu item, copy the selected text to the Clipboard by pressing the key combination  command-C. In the Finder, select
              Go ▹ Go to Folder...
    from the menu bar and paste into the box that opens by pressing command-V. You won't see what you pasted because a line break is included. Press return.

  • Upgraded 10.6.8 SMC Version (system):     1.12f5 to SMC Version (system):     1.16f11 and HP p2015 printer is nolonger recognized

    I upgraded 10.6.8 SMC Version (system):
    1.12f5 to SMC Version (system):
    1.16f11 and HP p2015 printer is nolonger recognized.
    on the latest update.
    I have another similar macbook pro that is running with the older version and it will access the printer.
    Are there issues with the latest 10.6.8 upgrades?
    Thanks,  bills

    Hi bills12!
    I have an article here for you that can guide you in troubleshooting this issue with your printer interaction with your computer:
    Troubleshooting printer issues in OS X
    http://support.apple.com/kb/ts3147
    Thanks for coming to the Apple Support Communities!
    Regards,
    Braden

  • I just downloaded adobe reader and can't print a pdf file

    i just downloaded adobe reader and cannot print a pdf file.

    Same or related issue.
    After installing latest updates of Mac Mavericks and Adobe Reader, I can't open pdfs downloaded from the web or print pdfs from the web. Using "export" doesn't help. Same with the print/pdf workaround.
    I uninstalled/reinstalled Reader. I indicated Adobe Reader as my default opener for pdf-type files. No help.
    I'm using Safari.

  • Photoshop CS4 and Mountain Lion Printing Question

    I recently downloaded CS4 onto my new Macbook Pro Retina running Mountain Lion and I am not able to print from CS4 to my Epson 3800 printer. When I hit the print button, the light on the Epson 3800 blinks one time but nothing happens.  The file does not even get sent to the printing queue.
    Photoshop CS4 otherwise works perfectly fine on my Macbook Pro Retina.  Additionally, all other applications on my Macbook Retina print perfectly fine on my Epson 3800.  For example, I can print from Aperture to the Epson 3800 just fine.  I am using the most recent Epson driver from the Epson website.
    Any suggestions would be greatly appreciated.

    Hi Peter,
    Since your Epson 3800 printer is working fine with other applications, one workflow work around would be to export your Photoshop file as another format (for example .jpeg, .png, .tiff or even .pdf depending on what your content is). By exporting it as another format, you can open it using other applications (such as Acrobar Reader, or Preview) and print from there. While this is not the most ideal lsolution, it should do the trick if you are in a rush to print.
    To help troubleshoot and solve this problem in the long run, you can take a look at this help page: Trouble Shooting Printing Problems, Photoshop CS4 Mac OS.
    This helpful page lists all the possible things you can do to reset or fix the problem, it also lists a number of alternatives.
    Hope this helps!
    Clarice

  • Can you provide text for the video, to be read and tried out at my speed?

    The video moves too fast, and assumes the listener knows terminology that he or she might not. Talk more slowly and clarify the terminology during the discussion.

    Which video are you referring to?
    Did you read the related SUMO Knowledge Base article (which is that)?

  • In need of reading and stripping out a href links in an off-line HTML file

    Hi there.
    I'm in need of some guidance with respect to the reading of a
    local
    (off-line) HTML file, in doing so I need to identfy all of
    the links held
    within the HTML file, ie., <a href...> ... </a>
    and have them populate a
    seperate list.
    My problem is in that in all of my years of using Director
    I've never dealt
    with external files to this kind of degree - and having take
    quite a break
    from Lingo for quite sometime as well, I'm kind of stuck as
    to where the
    heck I should start!!
    Any help/guidance would be hugely appreciated.
    Many thanks in advance.
    Thanks, Mark.

    Many thanks johnAq - your help is very much appreciated.
    Kind regards, Mark.
    "johnAq" <[email protected]> wrote in
    message
    news:gppbu1$cpu$[email protected]..
    > To get you started, there is some simple built-in Lingo
    (at least up unti
    > Director 10 - I don't have D11 and they changed the text
    engine so....)
    >
    > 1) Use Fileio to read in the html file into a string
    variable
    >
    > 2) Set the .html property of a #text member to the
    string variable text
    > you
    > read in from your file. This will automatically treat
    all of the links in
    > the
    > html and hyperlinks in the text member.
    >
    > 3) You can now access the .hyperlinks property of the
    text member, which
    > will
    > give you a list of all the links in the text - each
    entry in the list is a
    > list
    > of two items - the start and end chars of the hyperlink
    >
    > From there you should be able to rework things into a
    format you require
    >
    > hth
    >
    >
    > johnAq
    >

  • "switching of echoing characters" in System.in.read(), System.in.readLine()

    Hi,
    I am trying to create an effect in
    System.in.read() or
    System.in.readLine()
    by not echoing the characters, if anyone knows please let me know,
    thanx!!!!

    I raised this issue also in another thread.
    Actually I am pretty p.o. This issue pops up over and over again but the people at Sun systematically deny the problem and simply do nothing about it. I know, it's not as interseting as EE, 3D graphics or Swing, but it is asked for by many peaople over and over again.
    I simply don't understand what is so difficult in the method:
    System.in.setEcho(boolean) or System.in.setEcho(char)

  • Can an old iMac G3 drive running system 10.2.8 and system 9 be mounted in the secondary drive bay of a G4 800 Mhz running 10.4.11 and boot from the 10.2.8?

    I've done this and the G4 800 Mhz boots up from system 9 on the old iMac G3 just fine, but when I boot up from its system 10.2.8, it runs for only 5 minutes or so and the grey screen comes down telling me to re-boot.  I've run Norton on the system 9 disk and system 10 disk utilities on the system 10 disk of the old iMac G3 and all is fine with it.  Is there some incompatibilities with running the old iMac G3 230 Mhz from the G4 800 Mhz that causes this to happen?  I can access all my old files on the iMac G3 when I boot up with extensions off (holding down the shift key when I boot up), but I would like to be able to use the USB functions when I boot it up.

    It sounds like you have a Power Mac G4 Quicksilver 2002, and according to the program Mactracker, it should be able to run on the OS 9 and the OS 10.2.8.
    I don't know which version of Norton (Utilities?) you ran on the old iMac drive, but I suspect that might be the problem.  This is from the iMac Tray Loading Service Source Manual:
    HFS Plus Formatted Drives
    The hard drive in the iMac is formatted with HFS Plus (also referred to as Mac OS Extended format). It is important to note that Norton Utilities version 3.5 is not compatible with HFS Plus (or Mac OS Extended format), and in fact, can destroy data on the hard drive.
    Norton Utilities version 3.5.3 or 3.5.2 will not attempt to repair a drive formatted with Mac OS Extended format and versions 3.5.1 and earlier cannot recognize that a hard drive is in Mac OS Extended format and can result in hard drive corruption and loss of all data on the drive.
    Note: When diagnosing hard drive problems, it is important to verify whether or not the customer may have used the wrong disk repair software for their drive before assuming that the problem is hardware related.
    If you experience problems with a hard drive that has been formatted with HFS+, Apple Computer recommends using Disk First Aid 8.2 (which is included on the system software CD that ships with the iMac). Disk First Aid 8.2 can be used to recover data that may have been deleted by Norton Utilities. (See the Symantec Web site at NO LONGER A VALID LINK-REMOVED FROM ARTICLE for more information on Norton Utilities and Mac OS Extended format.)
    Some other disk utility and disk locking programs are incompatible with Mac OS Extended format. Before you attempt to use a disk utility or disk locking program, make sure the version you have is compatible with Mac OS Extended format. Check the documentation that came with the program or contact the manufacturer or the vendor that supplied the program.
    Use the Get Info command in System 8.1 to determine how a hard drive has been formatted. Drives formatted with HFS will appear as “Mac OS Standard”, while drives formatted with HFS+ will appear as “Mac OS Extended.”
    I hope some of this helps.
    Good luck.

  • Read and write with usb printer

    hello friends
                            i m new in labview . can any body advised me how to read and write with printer that have USB interface . because latest printer connection are usb based not parallel port based.
    any example or material.
    i shall be very grateful to u
    thanks

    Hi,
    It depends on what type of driver you are using, and how that driver communicates with you printer. 
    There are lost of different ways LabVIEW can interface with external hardware, either using all libary function node, ActiveX, .NET, etc.  It all depends on what type of driver you are using.
    Regards
    Seamus

  • Adobe Reader 9.3.1 prints incorrectly in Windows 7 x64 - HELP

    Adobe Reader 9.3.1 PDF document pages at half size and rotated 90 degrees.  If I set "Print as Image" under the Advanced print options, it does print correctly, although the resolution isn't very good.  This happens on several documents (stand alone files and from Internet Explorer both).  I am running Windows 7 64 bit.
    On my Vista 32 bit system, Adobe Reader 9.3.1 prints the same documents correctly on the same printer.
    Has anyone heard of this problem?  Is there a solution?

    I have some of the same problem
    with my Windows 7 64 bit computer. I
    get an error when sending a document to
    the PDF veiwer and am told to shut down
    Adobe Reader.  Is there a download to
    correct this problem?  Adobe Reader 9.3.1
    works fine with Windows XP on my 32 bit
    computer.

  • Upgraded to snow leopard and now cannot print

    I purchased an iPhone 4S which forced me to upgrade to snow leopard. I have two Epson printers and an Epson scanner.  Now I cannot print.
    I downloaded Epson updates for the new system from the Apple website hoping that would solve the problem.  It did not.
    Current print issues:
    The print dialogue boxes look like inDesign options, not photoshop or "regular" print options.
    I cannot print :  Error:/System/Library/Printers/Printjobmgr/Contents/MacOS
    Any suggestions on what to do next?  This is very frustrating. 
    Thanks in advance.

    Open the System Preferences program and select the Print tab. Delete the printers and then try installing the printers again.
    I don't know what you mean by:
    The print dialogue boxes look like inDesign options, not photoshop or "regular" print options.
    If this persists you might want to take screenshots and include them.

  • How to read and display a signal from my PIC Microcontr​oller onto Labview?

    Hi,
    I am doing a project on a Pulse Oximeter and i am trying to read and display the signal from my PIC Microcontroller on Labview? How do i go about doing it? I am using the PIC16F877 and also making use of the USART?
    How do i implement and initialise the USART in PIC16? What are the steps to be taken, please guide me through the process? The link provides information regarding the USART connection, initialisting and stuff? Is it correct to use these codes in my program?Link: http://ww1.microchip.com/downloads/en/AppNotes/007​74a.pdf
    Also, i am using the RS232 serial interface to connect to the PC? The connector i am using is the DB9 Connector. Which template and VI can i use? Am i supposed to use the NI-DAQmx and VISA? Also, for my USART connection, i am using the MAX232 Driver which is applicable for my application as i am working with +5V. So far, i have been reading and trying out on Labview and the steps i have taken are:
    1) Open a New VI and used the Instrument I/O(Read & Display) template?
    2) How do i configure the Instrument I/O Assistant Express VI to read the info from my device connected to COM1?
    3) I was reading the Labview Manual, 'Getting Started with Labview' and i was following the steps under Page 55, Communicating with an Instrument. Am i on the right track?
    4) How do i check and make sure that the port settings of the I/O Assistant and my PIC Micro Match
    Please help me out and guide me through the process. I am student at a polytechnic and i am very new to Labview and the software is used as a development tool for the project. I have a deadline to meet and i hope i can get a response as fast as possible. Your help will be kindly and greatly appreciated. I hope to hear from you guys soon.You can e-mail me all your answers at [email protected]
    Thank You
    Best regards,
    Ashwin
    Ashwin Kumar Mansukhani
    Attachments:
    Getting Started with Labview.pdf ‏901 KB

    Hi Ashwin,
    It is a good idea to first be able to communicate with the microcontroller using some sort of serial communication software such as "HyperTerminal" or "Procomm", etc. Refer to MicroChip's recommendations on this.
    Once that works, then you are ready to use LabView.
    Here is a link which covers many aspects of serial communication. Link - click here
    You probably received a development kit. They usually have a readily available interface. It's been a long time since I played with the PIC, but I seem to remember that you need to program the serial communication driver (as well as at least a bootloader) to get the serial communication going. The driver contains the necessary protocols so that you PC can have a machine conversation with the target (PIC).
    It sounds like a fun & interesting project. Please avoid to have replies to your personal email. By having the answers posted to this thread, you will get much more support and advice.
    Have fun,
    JLV

  • How to read and display a signal from my PIC Microcontroller onto Labview

    Hi,
    I am doing a project on a Pulse Oximeter and i am trying to read and display the signal from my PIC Microcontroller on Labview? How do i go about doing it? I am using the PIC16F877 and also making use of the USART?
    How do i implement and initialise the USART in PIC16? What are the steps to be taken, please guide me through the process? The link provides information regarding the USART connection, initialisting and stuff? Is it correct to use these codes in my program?Link: http://ww1.microchip.com/downloads/en/AppNotes/00774a.pdf
    Also, i am using the RS232 serial interface to connect to the PC? The connector i am using is the DB9 Connector. Which template and VI can i use? Am i supposed to use the NI-DAQmx and VISA? Also, for my USART connection, i am using the MAX232 Driver which is applicable for my application as i am working with +5V. So far, i have been reading and trying out on Labview and the steps i have taken are:
    1) Open a New VI and used the Instrument I/O(Read & Display) template?
    2) How do i configure the Instrument I/O Assistant Express VI to read the info from my device connected to COM1?
    3) I was reading the Labview Manual, 'Getting Started with Labview' and i was following the steps under Page 55, Communicating with an Instrument. Am i on the right track?
    4) How do i check and make sure that the port settings of the I/O Assistant and my PIC Micro Match
    Please help me out and guide me through the process. I am student at a polytechnic and i am very new to Labview and the software is used as a development tool for the project. I have a deadline to meet and i hope i can get a response as fast as possible. Your help will be kindly and greatly appreciated. I hope to hear from you guys soon.You can e-mail me all your answers at [email protected]
    Thank You
    Best regards,
    Ashwin
    Ashwin Kumar Mansukhani
    Attachments:
    Getting Started with Labview.pdf ‏901 KB

    Hi Ashwin,
    I am not familiar with the PIC Microcontrollers, but I am assuming you mean that you have the microcontroller sending out serial data that you want to read on another computer with LabVIEW. Please let me know if this is incorrect.
    What type of data is coming out of the serial port? Is it ASCII, or binary? The reason I ask this is that the serial communication in LabVIEW is done through a protocol called VISA, which uses ASCII data to send and receive. You can later convert this data into whatever form you need, but this is what it is designed to read and write.
    You can check the settings such as baud rate and data bits in a configuration utility called Measurement and Automation Explorer, or MAX. When you open up the MAX interface, you can expand the Devices and Interfaces entry on the left, and then expand the Ports entry to see your serial port. When you highlight this port, select the Port Settings tab at the bottom of the window, and you can see what the current settings are, and change them if you need to. You can also set these parameters in LabVIEW using the VISA Configure Serial Port VI.
    You can also test communication in MAX by right clicking on the correct port and choosing Open VISA Session. Then choose the Basic I/O light blue tab, and then go to the Read tab. When you click execute, it should read in what is coming from the serial port. This will allow you to verify that the correct information is coming in before even trying to acquire the data in the LabVIEW environment.
    In LabVIEW, the best resource to use the Basic Serial Write and Read example program that ships with LabVIEW. By examining the block diagram of this program, you will be able to see the basic programming flow of serial communication in LabVIEW.
    I hope this information was helpful! Please let us know if there's anything else we can help with.
    john
    Applications Engineer

  • Adobe Reader X stuck on "print to file"

    I have a problem with Adobe Reader 10.1.0 not saving my print settings after I close it.  I am running Windows Vista and trying to print to a RICOH printer/scanner/copier machine.  I checked "Print to file" by accident once and tried to print, and now every time I open Adobe Reader and try to print something, I have to uncheck "Print to file."  It is also stuck on "Print as image."  I have tried restoring the default settings on the printer, changing the default printer, and repairing the installation.  Checking and unchecking "Restore last view settings when reopening documents" doesn't make a difference.
    Has anyone else had this problem?  Is there a way to change the default so that "print to file" and "print as image" remain unchecked?  Thanks!

    I just fixed this issue. Running Adobe Reader X on Win7 x64 Enterprise.
    Locate HKEY_CURRENT_USER\Software\Adobe\Acrobat Reader\10.0\PrefsDialog and modify the key "aLastPrefsPanel" to say "Display". I found on the troubled PC it was set to "Startup"
    In your cases running 10.1 the registry path may be "10.1" rather than "10.0"
    That should do the trick.
    Peter

Maybe you are looking for

  • ICloud working only selectively on my iPod Touch (4th G)?

    This is a bit weird and I'd appreciate any suggestions.  All of a sudden, my iPod Touch isn't getting full iCloud support, it seems.  Photostream works fine, I think, and contacts are syncing with my other devices.  But iBooks are no longer syncing (

  • Can't save an edited PDF to the same folder it originated from

    Can't save an edited PDF to the same folder it originated from. Error "cannot save the document is read-only or is open by someone else" and then it prompts to save the document to another folder or change the name of the document.  This is not what

  • Cannot find the configuration file bc4j.xcfg

    I have compiled my Business Components Project in JDeveloper and all Projects that reference that BC Project are pointing to the correct classes directory, but I am still getting the following error: JBO-33001: Cannot find the configuration file /com

  • Loss in Potential Download Speed

    Hi, I used to have an average download speed of 2.x Mbps going towards 3 Mbps, and continuing on months later I am now at an average speed of 1.2 - 1.4 Mbps. I don't need to follow any diagnostics advised by Sky as the same setup has been used since

  • My iMessage won't work can you please help

    My iMessage just stopped work today and can't get it to work again help please