The problem is it is still giving the output as 3 sometimes which should not be.
Kindly help me with this snippet
//CODE SNIPPET
int number1=4;
while(number1>3)
{
number1=(int)(Math.random()*10);
}
System.out.print(number1);
Printable View
The problem is it is still giving the output as 3 sometimes which should not be.
Kindly help me with this snippet
//CODE SNIPPET
int number1=4;
while(number1>3)
{
number1=(int)(Math.random()*10);
}
System.out.print(number1);
Can you show what the code currently does and explain what is wrong with its output and show what you want the output to be.
Please edit your post and wrap your code with
[code=java]
<YOUR CODE HERE>
[/code]
to get highlighting and preserve formatting.
So, this is how I read your snippet.
variable number1 equals 4
while number1 is greater than 3
number1 is a random double from 0 to 1 multiplied by 10 and converted to an int.
display number1
from what you are saying, you are not expecting the value 3 to show up.
so what happens after number1 is set to 3 by the random equation?
This link may help you find the answer:
Equality, Relational, and Conditional Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)