Results 1 to 3 of 3
  1. #1
    averagezack is offline Member
    Join Date
    Jun 2015
    Posts
    2
    Rep Power
    0

    Default new to java and i have a minor problem

    import java.util.Scanner;



    public class fiddle {

    public static void main(String[] args) {
    // TODO Auto-generated method stub

    char nnn = '?';
    int r = 1;
    r = r + 1;


    Scanner SCN = new Scanner (System.in);
    System.out.println( "How many years are in a century" + nnn );

    int T = SCN.nextInt();

    while ( T != 100) {

    System.out.println( "Try again!");
    T = SCN.nextInt();}

    if (r == 5) {System.out.println( "you fail, start again");
    }


    Here's my code. A'll i want to do is basically have the "you fail" appear after 5 attempts of the question. What's the simplest way of doing this? Thanks in advanced people.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: new to java and i have a minor problem

    Update r inside the loop. But when they fail, you need to exit the loop. Read about loop control in the java tutorials in my signature. Click on the really big index for specific help.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    averagezack is offline Member
    Join Date
    Jun 2015
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Urgent help with minor java project
    By joygoku08 in forum New To Java
    Replies: 3
    Last Post: 02-07-2013, 04:56 AM
  2. Replies: 2
    Last Post: 06-25-2012, 08:01 PM
  3. Need help with this minor problem.
    By juxta in forum New To Java
    Replies: 12
    Last Post: 04-30-2012, 11:16 PM
  4. Some minor doubts about JAVA
    By naveenpaul1987 in forum New To Java
    Replies: 9
    Last Post: 03-16-2011, 11:53 AM

Posting Permissions

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