Results 1 to 3 of 3
  1. #1
    activex is offline Member
    Join Date
    Oct 2009
    Posts
    1
    Rep Power
    0

    Default Show all numbers witch divides by 30

    Hi. This is my first post, I just started programming in uniersity, so please be soft... :)

    I am giving to program number from 1- 10000 it must print out all numbers witch can divide by 30.
    Something is terrible wrong with loop statement in end. I hope you can help me.

    Java Code:
    import java.util.Scanner;
    
    public class CheckNumberRange
    {
    
    	public static void main(String[] args)
    	{
    		Scanner keyboard = new Scanner(System.in);
    
    		System.out.println("Write number between 1 - 10'000: ");
    		
    		
    		int x = keyboard.nextInt();
    		int legalNumbers = x / 30;
    		
    		int allNumbers = 0;
    		
    	
    		
    			
    		if
    
    		(x > 0 && x < 10000)
    		{
    
    			System.out.println("Number is correct");
    		}
    
    		if (x < 0 || x > 10000)
    		{
    
    			System.out.println("Sorry you entered wrong number");
    		}
    		
    		{
    		//check if x is working
    			System.out.println("Entered number was: " + x);
    			System.out.println("Number " + x + " divides " + legalNumbers + " times with divider 30");
    			
    			
    			System.out.println("___________________________________________");
    			
    			
    			//show all numbers witch are divided with x
    			
    			for (int i=30; i<=1000; i = 30 + i)
    				 allNumbers = i+x%30;
    				
    			
    			System.out.println("Numbers witch are dividable with 30 are " + allNumbers);
    		}
    		
    				
    		
    
    	}
    
    }

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    1.) Your first if check is useless.
    2.) allNumbers is just an integer. It can only hold one integer at a time. It doesn't make sense to call it allNumbers in the hope that it will somehow be able to print all numbers.
    4.) Your for loop should not go to 1000, should it? Shouldn't go as far as x, the input number?
    3.) Better print the number at each pass of the loop. Loop from 1 to x and at each pass print out the number only if it is divisible by 30.

  3. #3
    atom86 is offline Member
    Join Date
    Sep 2009
    Location
    Italy, Turin
    Posts
    39
    Rep Power
    0

    Default

    instead of the second if() statement you could use the else of the first if...much simple

Similar Threads

  1. the component does not show
    By shruti in forum AWT / Swing
    Replies: 8
    Last Post: 07-08-2009, 12:21 PM
  2. Jbutton do not show up
    By javaTech in forum AWT / Swing
    Replies: 15
    Last Post: 05-12-2009, 12:22 PM
  3. printing two smallest numbers from a series of numbers
    By trofyscarz in forum New To Java
    Replies: 2
    Last Post: 10-14-2008, 11:46 PM
  4. netbeans 6.0 not show commpunent or show blank page
    By fahimaamir in forum NetBeans
    Replies: 1
    Last Post: 01-26-2008, 06:20 AM
  5. show a RTF FORMAT
    By Jack in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2007, 03:37 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
  •