Results 1 to 2 of 2
Thread: While loop problem
- 01-12-2011, 02:08 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 5
- Rep Power
- 0
While loop problem
how do I make this for loop into a while loop?
Scanner sc = new Scanner(System.in);
System.out.print("Enter start number: ");
int start = sc.nextInt();
System.out.print("Enter last number: ");
int end = sc.nextInt();
System.out.println();
int count = 0;
for (int i = start; i <= end; i+=3) {
System.out.print(i + " ");
count++;
if (count==10) {
count = 0;
System.out.println();
}
}
// it prints every third number (user input numbers).... and I want to do the same with a while loop but I can't figure it out...help please!
- 01-12-2011, 02:13 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,408
- Blog Entries
- 7
- Rep Power
- 17
As you could've known from your text book, a for-loop like this:
is equalvalent to a while-loop like this:Java Code:for (<init>; <cond>; <incr>) <statement>;
kind regards,Java Code:<init>; while (<cond>) { <statement>; <incr>; }
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Problem with a for loop
By ile4 in forum New To JavaReplies: 3Last Post: 12-02-2010, 02:23 PM -
simple line problem / for loop problem
By helpisontheway in forum New To JavaReplies: 1Last Post: 11-17-2009, 06:12 AM -
Some while loop problem need help
By shaggyoo7 in forum New To JavaReplies: 4Last Post: 01-14-2009, 07:16 PM -
Loop Problem
By jralexander in forum New To JavaReplies: 4Last Post: 12-02-2008, 07:08 AM -
For loop problem
By mcal in forum New To JavaReplies: 32Last Post: 01-25-2008, 03:51 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks