Can you help w/ simple io problem?

i have this code and am expecting it to do a couple of things. first the code.
import java.io.*;
class BasicTests2 {
public static void main(String[] args) {
String input="";
InputStreamReader converter = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(converter);
System.out.println("Please enter your name: ");
while((System.in.read())!=-1) {
input=in.readLine();
System.out.println(input);
} // end while
} // main()
} // BasicTests2
my problems. one, when i enter a -1 the program does not exit. and secondly why does it cut the first char i enter when it echoes my entry back to me???
thanks for any help,
erik

my problems. one, when i enter a -1 the program does
not exit. The InputStream.read() method returns a -1 when the end of the stream has been reached. If the user enters a -1, then the end of the stream has not been reached. Entering a CTRL+Z will send the end of file marker indicating that the end of the stream has been reached.
and secondly why does it cut the first char
i enter when it echoes my entry back to me???This is because your code is reading in a byte of data (or one character), and then reading in a line of characters to echo back via System.out.println().
Perhaps you could try something like this:
import java.io.*;
class BasicTests2 {
public static void main(String[] args) {
String input= new String();
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter your name (-q to quit) : ");
try {
input=in.readLine();
while(input !=null && !input.equalsIgnoreCase("-q")) {
System.out.println(input);
input=in.readLine();
} // end while
} catch (Exception e) {
e.printStackTrace();
} // main()
} // BasicTests2

Similar Messages

  • Can you help I was having problems with my iPod so I restored it but I accidentally set it up as a new iPod is there any way to restore it from an old  backup when I right click iPod in iTunes there isn't one anyway to recover one or find it on computer

    Hi can you help I was having problems with my iPod so I restored it but I
    accidentally set it up as a new iPod is there any way to restore it from an old
    backup when I right click iPod in iTunes there isn't one anyway to recover one
    or find it on computer

    The following says how to restore from backup.
    iOS: How to back up
    If you go to iTunes>Preferences>Devices you can see if you have an iTunes backup. You need one dated before or the exact time you started the restore.

  • Guys can you help me, i have problem regarding on syncing of my apps in my ipad it usually stops on step 4 saying determining apps to sync then its stop... can anyone have an idea..i already reset the setting of my ipad

    ys can you help me, i have problem regarding on syncing of my apps in my ipad it usually stops on step 4 saying determining apps to sync then its stop... can anyone have an idea..i already reset the setting of my ipad

    Hello Violet03,
    Thank you for using Apple Support Communities!
    I would recommend a few things here. If you havent already restart both your computer, and the iPad.
    iPhone, iPad, iPod touch: Turning off and on (restarting) and resetting
    http://support.apple.com/kb/ht1430
    Restarting your device
    Press and hold the Sleep/Wake button for a few seconds until the red "slide to power off" slider appears, and then slide the slider.
    Press and hold the Sleep/Wake button until the Apple logo appears.
    If that doesnt work then close all the apps that are running on the iPad with this process:
    From the Home screen, click the Home button twice.
    Tap and hold on the app.
    When it starts to jiggle, tap the to close it.
    Double-click the Home button and try opening the app again.
    From: iOS: Force an app to close
              http://support.apple.com/kb/ht5137
    And if the issue persists it might be a good idea to backup and restore your iPad in iTunes with this article.
    iOS: How to back up and restore your content
    http://support.apple.com/kb/HT1766
    All the best,
    Sterling

  • TS3694 hello i am trying to update my phone . i am connecting it to itunes but it is giving error 3194 . can you help me resolve this problem please.

    hello i am trying to update my phone . i am connecting it to itunes but it is giving error 3194 . can you help me resolve this problem please.

    Hi ali hakim,
    Welcome to the Support Communities!
    The article below may be able to help you with this issue.
    Click on the link to see more details and screenshots.
    iOS: Restore error 3194 or 'This device isn't eligible for the requested build'
    http://support.apple.com/kb/TS4451
    This occurs when iTunes is unable to communicate with the update-and-restore server (gs.apple.com). This is most likely because it is being blocked, redirected, or interrupted by security software, hosts-file entries, or other third-party software.
    Cheers,
    - Judy

  • I cannot get my pdf files to open can you help me with my problem?

    My pdf files will not open can you help me?

    I don't know if we can help you. This is almost certainly the wrong forum, but perhaps we can help you there too. Let's start with some questions
    1. What software (app) are you using to try to open the PDF files, including version number if you know it?
    2. If you are using a browser, what is it?
    3. Are you on Mac or Windows?
    4. Is the PDF file on your hard drive (own computer), on a web site, or somewhere else?
    5. What EXACTLY happens when you try to open the PDF? If you get a message, what is the message IN FULL?
    Please answer all questions carefully.

  • Can you help with my printing problem?

    Hello,
    I have been using Adobe reader to run my crafting cds for a long time now. However recently i have had issue with printing. When i press print adobe reader tells me that there is no printers installed yet my printer is installed an set at default!
    Can anyone help me print again pls?

    How about updating to Firefox 4.0.1? There was a flaw in b12 that caused problems with spacing of the type when printing, IIRC. Or maybe that was with b11? Regardless the Firefox4 release version was released two months ago, tomorrow to the day.

  • Hello, i have an issue, i am crying to purchase lion and the first doesnt appear the model of my computer, and at the second one doesnt accept the serial number. can you help my whit this problem?

    can you hepl my?
    <Email Edited by Host>

    To download Lion your computer must have OSX 10.6.8 and must have Core Duo 2 Intel.
    Para descargar el león su ordenador debe tener OSX 10.6.8 y debe tener Core Duo 2 Intel
    You can purchase Lion on a USB stick from the Apple Store (more expensive).
    Usted puede comprar el león en un palillo de USB de Apple Store (más costoso)
    It's not a good idea to post your email address - it's an invitation to Spam - and I've asked the Hosts to remove it.
    No es una buena idea fijar su dirección de correo electrónico - él es una invitación Spam - y he pedido que los ordenadores principal lo quiten.
    (Translation by computer.)
    (Traducción por el ordenador.)

  • Can you help me with this problem? Please!

    I had just created this program that calculates the amount due from an international phone call. and I was wondering what I can do to get the program to execute when the user inputs let's say 3min and some amount of seconds. The program works when the number of minutes the call lasted is an integer, but it does not when the number of minutes the call lasted is lets say 4min30sec. Is there anyway I can get my program to execute both minutes and seconds? Help is very appreciated.
    Here's the program:
    import java.io.*;
    import java.text.DecimalFormat;
    public class PhoneCallBilling_Lab4
         static BufferedReader keyboard = new
         BufferedReader(new InputStreamReader(System.in));
         //Named constants
    static final double CONNECTION_FEE = 1.99;
    static final double FIRST_THREE_MIN_FEE = 2.00;
    static final double COST_OF_EACH_ADDITIONAL_MIN = 0.45;
         public static void main(String[] args) throws IOException
         //Variable declaration
    int noOfMinCallLasted;
    double amountDue;
    DecimalFormat twoDigits =
    new DecimalFormat("0.00");
    System.out.println("This program computes an international phone call.");
    System.out.print("Enter the number of minutes the call lasted: ");
    noOfMinCallLasted =
    Integer.parseInt(keyboard.readLine());
    System.out.println();
    if (noOfMinCallLasted<= 3)
         amountDue = CONNECTION_FEE +
         FIRST_THREE_MIN_FEE;
    else
    amountDue = CONNECTION_FEE +
    FIRST_THREE_MIN_FEE +
    (noOfMinCallLasted - 3) * COST_OF_EACH_ADDITIONAL_MIN;
    System.out.println("The number of minutes the call lasted was "
              + noOfMinCallLasted);
    System.out.println("Amount due = $"
    + twoDigits.format(amountDue));
    }

    How about converting the minutes to seconds and doing
    your calulations all in seconds?ok. I am going to try that but don't you think that it would be quite cumbersome if I was to have someone actually input information. They would have to go through the entire process of trying to figure out how many minutes is in a second and all of the other problems that may occur. If I didnt have to consider all possibilities when executing this program I could leave it as is. However, I have to. And the problem states that we (as in students) have to get the user to input the number of minutes and seconds and the program has to execute.

  • Hi there, can you help me with carrier problem

    Hi! I am having problem with my carrier in iPhone 4.
    I can't make and receiver call. I was asked to restore it from iTunes. I have restore my phone 4 times but still having the same problem. Could someone suggest me how I can fix this problem. Thanks

    Apple has a troubleshooting assistant here that may help:
    http://www.apple.com/support/iphone/assistant/calls/
    If not, then you may need to call your carrier as Tim suggested.
    Regards.

  • Can you help me with activation problems with Photoshop in CS2?

    I'm running a titanium powerbook, G4 and Mac OSX 10.4.11. When I launch Photoshop CS2 this happens:
    First, an error message appears in a dialog box which says exactly this: <One or more files in the Adobe Application Support folder, necessary for running Photoshop, are missing. Please run the Photoshop installer and re-install Photoshop.> I click the OK button.
    The Adobe Activation screen shows up next. If I click Activate at the bottom of the Internet Activation screen, I get this: <Activation Unsuccessful. We were unable to activate Adobe Creative Suite. Click the Phone Activation button to speak with one of our Customer Care representatives.> At the bottom left of the screen, it says <Error code: 93:-12> I click the Phone Activation button.
    The automated system fails to recognize some part of the Serial Number and Activation Number process and I speak with a person.
    After more than an hour of being passed from representative to representative, it is determined that they no longer support CS 2, and that this forum is the best place to go for help.
    I'm counting on you, P'shopistas! How can I activate?
    Thanks in advance to all!!!
    Enkisma

    I woud try two things.
    One I would uninstall the application to do so I would look in the Applications/Utilities/Adobe Installers and run the Installer to remove the Photoshop CS 2 application.
    I would then look in the Users/Username/Library/Preferences and remove anything connected to this version of Photoshop same with Users/Username/Library/Cache and Users/Username/Library/Application Support/Adobe and remove anything related to PS.
    Then reinstall.
    if that does not work then do an archival reinstal of the system an d then reinstall.
    Most important is that this software is not activated on two other computers or you will not be able to install and activate.

  • Can you help with a layer problem?

    I have a photograph. It has a white background. I want to separate the white background from the photograph. The photograph and the white layer are on layer 0. I cannot separate the two. I think I want to raise the photograph to layer 1. Then I can use the separation routine. I have spent about 10 hours messing with without success. This is a 143 K file so I cannot download it. Assume I know nothing which is close to the truth. Step by step would be wonderful.
    Thanks in advance.

    It all depends on the image. Some tools I'd use are the quick selection tool magic wand, the lasso, the pen tool, or channels, refine edges depending on the image.
    If the image is simple:
    1) double-click the background layer's thumbnail in the layers panel to make a layer out of it.
    2) select the background (if it is white, it should be easy) with the quick selection tool or the magic wand.
    3) invert your selection (select>invert, or CTRL+Shift+I
    3) click the create layer mask icon in the layers panel (white circle inside a grey rectangle)
    Searching for "remove background" will give you many results in Google that you could explore.
    Also, you will need to save the image in a format that supports transparency, like PNG, Tiff, PSD, but it also depends what you want to do with the image.

  • When setting up adobe element 13 and entering my serial number, a pop up says my serial number is incorrect.  Can you help me with my problem?

    How can I continue setting up photoshop element 13 when an error message says my serial number is incorrect?

    You want the Photoshop Elements forum:
    Photoshop Elements
    Are you using a Mac serial number for a PC or vice versa?

  • Can you help with my ipad problem?

    I first set my ipad up with a comuter now i have a new laptop how do i reset it up without losing everything? I cant update it to the new software because it wont let me backup it up. I have no clue what to do.

    If you still can't get things going try this:
    Transfer purchase from iPad to computer
    http://support.apple.com/kb/ht1848
    Backup
    http://support.apple.com/kb/ht1766

  • Can you help with a Superdrive problem?

    DVD-R disks that I have burned and finalised on an LG PVR are not recognised by my new iMac external superdrive. This was not a problem with my previous iMac with internal dvd drive. Is there a solution please?

    Hmm, from the customer reviews here, I  think you need a different Optical drive...
    http://www.cnet.com.au/lg-ms408-hd-dvr-339298308.htm
    http://eshop.macsales.com/shop/firewire/optical-drives/

  • Can you help with a Trash problem?

    I recently upgarded to 10.6.8 and all has been well.  But now I am having a Trash problem.  I can't drag to trash.  A list comes up, showing 'preparing to move to Trash', with a blue and white flashing line, apparently for every item..  But it has been running every time the machine is awake, since yesterday.  There is no way to delete it and, in the meantime, I can't put things in the trash or empty it.  It seems to be stuck in 'preparing' mode.  Can anyone tell me how to deal with this?  Please?

    Sorry, I should have read the side bars first, but didn't notice them.  The old eyes don't work as well anymore.  Anyway, I resolved the problem by following previous advice and apologize for taking up your time to read my problem.  Thanks!

Maybe you are looking for