Results 1 to 4 of 4
Thread: Java: While loop help
- 11-05-2008, 03:00 AM #1
Member
- Join Date
- Nov 2008
- Posts
- 1
- Rep Power
- 0
Java: While loop help
Hello,
I need to write a program that prints down the numbers from 66 to 33 in the screen. Also the program should not print out number 44. This is the problem; I can get it to print the numbers from 66 to 33 but no without the 44. I know I should insert something like count != 44... but I don't know where and I have alredy tried everything. My code so far is:
import java.util.*;
public class problem4{
public static void main (String[] args){
int num;
num = 44;
int sum = 1, count = 67;
while (count > 33){
count = count - sum;
System.out.println(count);
num != count;
}
}
}
Thanks in advance.
- 11-05-2008, 03:09 AM #2
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
You should read up on if-statements. I'm surprised that you're trying to use a loop before even knowing how to use a conditional statement properly.
The if-then and if-then-else Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)
- 11-05-2008, 03:45 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You should study more about conditional handling using loops.
Java Code:public static void main(String[] args) { int num = 66; while(num >= 33) { if(num != 44) System.out.println(num); num--; } }
- 11-05-2008, 03:48 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Brake you requirements into loops, then it's easy to workout.
Similar Threads
-
java recursion infinite loop
By tony404 in forum Advanced JavaReplies: 9Last Post: 10-03-2008, 01:16 PM -
Help with loop in java
By trill in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:36 AM -
Help, loop with java
By cachi in forum New To JavaReplies: 5Last Post: 08-01-2007, 06:03 AM -
Enhanced For loop In Java
By goldhouse in forum Advanced JavaReplies: 1Last Post: 05-06-2007, 04:26 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks