# Thread: Show all numbers witch divides by 30

1. Member
Join Date
Oct 2009
Posts
1
Rep Power
0

## 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. Senior Member
Join Date
Aug 2009
Posts
2,388
Rep Power
10
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. Member
Join Date
Sep 2009
Location
Italy, Turin
Posts
39
Rep Power
0
instead of the second if() statement you could use the else of the first if...much simple

#### Posting Permissions

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