Abdelrahman Mohamed Abdelrahman Mohamed - 1 year ago 122
Java Question

how to initialize an int variable with in between 2 values in Java

so I'm totally new at java, and i'm facing a little problem that some times i need to declare a numerical variable in between two values like

int x>=2&&x<=20;
but i can't find a way to do that ... for example i have this problem to solve:

Given an integer,N, print its first 10 multiples. Each multiple N*i (where 1 <= i <= 10) should be printed on a new line in the form: N x i = result.


2 <= N <= 20

so ... how can i solve that, and how can I initialize "int variable" in between two values?

Answer Source

It makes no sense to "initialize a variable between 2 values", as a variable can have only 1 value at a time.

You should give the different possible values to the variable one by one :

int i=1;
   System.out.println("Nxi = " +(N*i));

If you don't want to keep your i variable after you can use a for loop:

for(int i=1; i<= 10; i++){
   System.out.println("Nx"+i+" = "+(N*i));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download