Results 1 to 2 of 2
  1. #1
    mike28 is offline Member
    Join Date
    Oct 2011
    Posts
    20
    Rep Power
    0

    Default Problem Displaying The Output After The While Loop

    I don't know why but once i try to enter "Yes" it doesn't do anything and i want it to print the output

    import java.lang.*;
    import java.lang.Object.*;
    import java.util.Scanner;
    import java.io.*;
    public class InputWhileloop
    {
    public static void main(String[] args)throws IOException
    {
    System.out.print("Would you like Continue (Yes/No): ");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String hit = "";
    String hit2 = "";
    hit = br.readLine();
    while(hit=="yes"|| hit2 == "yes")
    {
    System.out.println("Testing");
    System.out.print("Would you like Continue (Yes/No): ");
    BufferedReader be = new BufferedReader(new InputStreamReader(System.in));
    hit2 = be.readLine();
    }
    }
    }

  2. #2
    Koala is offline Member
    Join Date
    Oct 2011
    Posts
    22
    Rep Power
    0

    Default Re: Problem Displaying The Output After The While Loop

    You can't compare Strings using ==. You have to use while(hit.equals("yes") || hit2.equals("yes"))

Similar Threads

  1. getting incorrect output nested for loop
    By leoshiner in forum New To Java
    Replies: 2
    Last Post: 05-02-2011, 10:29 PM
  2. for loop output
    By maknib in forum New To Java
    Replies: 5
    Last Post: 03-18-2011, 05:49 PM
  3. Displaying println output on GUI
    By SCCY in forum AWT / Swing
    Replies: 1
    Last Post: 08-09-2010, 01:34 PM
  4. displaying a formatted output on a jTextField
    By techbossmb in forum AWT / Swing
    Replies: 1
    Last Post: 09-24-2009, 04:56 PM
  5. No output displaying
    By Rgfirefly24 in forum New To Java
    Replies: 6
    Last Post: 04-27-2008, 08:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •