Results 1 to 3 of 3

Thread: Starting out

  1. #1
    Coltraine12 is offline Member
    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Question Starting out

    So, I just started programming with Java and maybe I'm getting ahead of myself but still. My question is this: how do I recall an earlier line? This is what I have as my code so far:

    import java.util.Scanner;
    public class SimpleTest
    {

    public static void main(String [] a)
    {
    Scanner kbd = new Scanner(System.in);
    System.out.println("This program is a simple test.");
    System.out.println("Please imput your name:");
    String name = kbd.nextLine ();
    System.out.println("Hello " +name+ " Are you ready to take the test?");
    String ans1 = kbd.nextLine ();
    if (ans1.equals ("Yes"))
    System.out.println("good, lets begin.");
    else if (ans1.equals ("No"))
    System.out.println("Ok, please come back when you are ready.");
    else if (ans1.equals ("yes"))
    System.out.println("good, lets begin.");
    else if (ans1.equals ("no"))
    System.out.println("Ok, please come back when you are ready.");
    else
    System.out.println("I'm sorry, " +ans1+ " is not a recognizable command. Please answer with either Yes or No");
    }

    }

    What I want to do, specifically, is to have the last line redirect back to the "are you ready to take the test?" line.

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default Re: Starting out

    Please use [code] tags [/code] when posting code.
    You'd normally use a loop:
    Java Code:
    do
       prompt user
       get input from user
    while input invalid
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,192
    Rep Power
    19

Similar Threads

  1. Need help starting a program.
    By cagipple in forum New To Java
    Replies: 2
    Last Post: 09-19-2011, 07:35 PM
  2. Starting Out...
    By maknib in forum Java Gaming
    Replies: 1
    Last Post: 11-11-2010, 08:15 PM
  3. Help with starting program please
    By SF163 in forum New To Java
    Replies: 5
    Last Post: 11-07-2009, 03:33 PM
  4. Starting with Databasing
    By DavidG24 in forum JDBC
    Replies: 3
    Last Post: 09-13-2009, 08:51 AM
  5. just starting
    By specbailey in forum New To Java
    Replies: 23
    Last Post: 08-13-2007, 11:25 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
  •