Results 1 to 5 of 5
- 10-08-2012, 11:18 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 3
- Rep Power
- 0
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.
- 10-08-2012, 11:40 PM #2
Re: having issue with user input and using while loop
See the tutorial: The for Statement (The Java™ Tutorials > Learning the Java Language > Language Basics)i cant get it to loop
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 ForumIf you don't understand my response, don't ignore it, ask a question.
- 10-08-2012, 11:50 PM #3
Member
- Join Date
- Oct 2012
- Posts
- 3
- Rep Power
- 0
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
- 10-08-2012, 11:53 PM #4
Member
- Join Date
- Oct 2012
- Posts
- 3
- Rep Power
- 0
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.
- 10-09-2012, 01:06 AM #5
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
-
need to create loop to force user to input integer
By Tolks in forum New To JavaReplies: 26Last Post: 05-10-2011, 12:31 AM -
Making a loop and creating variables based off of user input
By seanfmglobal in forum New To JavaReplies: 2Last Post: 01-13-2011, 05:43 AM -
Scanner user input not working in conjunction with while loop.
By TheNadz in forum New To JavaReplies: 5Last Post: 11-27-2010, 03:49 AM -
[SOLVED] User Input - loop
By new person in forum New To JavaReplies: 4Last Post: 02-22-2009, 10:02 PM -
loop when there is no user-input
By becky in forum New To JavaReplies: 12Last Post: 02-02-2009, 10:02 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks