Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Help: 1 is greater than 3?

  1. #1
    atac57 is offline Member
    Join Date
    Jan 2012
    Posts
    24
    Rep Power
    0

    Default Help: 1 is greater than 3?

    Every time I enter a number less than 3 for the variable "items" I still get the statement in the if condition (items > 3). Whats going on?

    Java Code:
    import java.util.Scanner;
    
    class Switch {
    	public static void main (String args[]){
    		Scanner scan = new Scanner (System.in);
    		
    		int items, total;
    		int time, time2, time3;
    		
    		System.out.println("Number of items in microwave: ");
    		items = scan.nextInt();
    		
    		System.out.println("Heating time: ");
    		time = scan.nextInt();
    		
    		if (items == 1)
    		{
    			System.out.println("Recommended heating time: " + time);
    		}
    		
    		if (items == 2)
    		{	
    			total = time/2;
    			time2 = total + time;
    			System.out.println("Recommended heating time: " + time2);	
    		}	
    		
    		if (items == 3)
    		{
    			time3 = time * 2;
    			System.out.println("Recommended heating time: " + time3);			
    		}
    		
    		if (items > 3);
    		{
    			System.out.println("Microwaving more than 3 items at once is not recommended.");
    		}	
    		
    		
    	}
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help: 1 is greater than 3?

    You're if block is being short-circuited by an errant semi-colon. Can you spot it?

  3. #3
    atac57 is offline Member
    Join Date
    Jan 2012
    Posts
    24
    Rep Power
    0

    Default Re: Help: 1 is greater than 3?

    I'm such a dummy! Thank you.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Help: 1 is greater than 3?

    Quote Originally Posted by atac57 View Post
    I'm such a dummy! Thank you.
    You sure would be if you were the only one who did this. Fortunately or unfortunately, the reason that I know this so well and can identify it so quickly is because...
    quad64bit likes this.

Similar Threads

  1. Replies: 9
    Last Post: 06-17-2012, 04:13 AM
  2. Problem while writing to file, size greater than 15MB ..?
    By prabhurangan in forum New To Java
    Replies: 3
    Last Post: 12-30-2008, 05:28 PM
  3. Replies: 1
    Last Post: 06-30-2008, 07:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •