Results 1 to 5 of 5
  1. #1
    barqcider is offline Member
    Join Date
    Oct 2012
    Posts
    18
    Rep Power
    0

    Default having issue with user input and using while loop

    hi all, im new to java in general and this issue has stumped me. i basically need to get a user to enter any number and multiply it upto 10 (meanin num *1, all the way to 10). so far i gotten so user is prompted to enter the number, but i cant get it to loop. i did declare the variable num as an int.

    this is what i did:

    System.out.println("\n\nenter a number");
    num = readit.nextInt();

    i did sum= num * count
    count++, but when command prompts, i enter a number and it doestn multiply it like i wanted. any help is appreciated.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: having issue with user input and using while loop

    i cant get it to loop
    See the tutorial: The for Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)
    and The while and do-while Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)

    If you want help with your program you need to post all the the code that shows what it does and its output.
    Be sure to wrap the code in code tags: BB Code List - Java Programming Forum
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    barqcider is offline Member
    Join Date
    Oct 2012
    Posts
    18
    Rep Power
    0

    Default Re: having issue with user input and using while loop

    public static void main (String[]args)
    {
    Scanner readit = new Scanner(System.in);
    int count = 1;
    int num =0;
    int sum =0;
    while (count < 11)
    {
    num = 7;
    sum = num *count;
    System.out.println(num+" times " + count + " is " + sum);
    count = count + 1;
    }// end while for part one.

    System.out.println("\n\nenter a number");
    num = readit.nextInt();
    while ( count < 11)
    {

    sum = num * count;
    System.out.println(num + " times " + count + " is : " + sum);
    count++;
    }


    }//end class
    }//end main


    thats what i got so far. it just keeps exiting out when i enter a number. i know im missing a piece

  4. #4
    barqcider is offline Member
    Join Date
    Oct 2012
    Posts
    18
    Rep Power
    0

    Default Re: having issue with user input and using while loop

    i appreciate the links. right now its specific i use a while, ill get to using the for soon in a different part of my project.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default Re: having issue with user input and using while loop

    Please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    What is shown on the console when you execute the program? Please copy and paste the contents of the console here.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 26
    Last Post: 05-10-2011, 01:31 AM
  2. Replies: 2
    Last Post: 01-13-2011, 06:43 AM
  3. Replies: 5
    Last Post: 11-27-2010, 04:49 AM
  4. [SOLVED] User Input - loop
    By new person in forum New To Java
    Replies: 4
    Last Post: 02-22-2009, 11:02 PM
  5. loop when there is no user-input
    By becky in forum New To Java
    Replies: 12
    Last Post: 02-02-2009, 11:02 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
  •