Results 1 to 4 of 4
  1. #1
    alfredoooddd is offline Member
    Join Date
    Nov 2008
    Posts
    1
    Rep Power
    0

    Default 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.

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    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)

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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--;
            }
        }

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. java recursion infinite loop
    By tony404 in forum Advanced Java
    Replies: 9
    Last Post: 10-03-2008, 01:16 PM
  2. Help with loop in java
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:36 AM
  3. Help, loop with java
    By cachi in forum New To Java
    Replies: 5
    Last Post: 08-01-2007, 06:03 AM
  4. Enhanced For loop In Java
    By goldhouse in forum Advanced Java
    Replies: 1
    Last Post: 05-06-2007, 04:26 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
  •