Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

1. ## Scanner Issues: Read for more detail, thanks.

```while(a < amount){

int num1 = 2 + (int)(Math.random()*23);
int num2 = 2 + (int)(Math.random()*23);
int num3 = 2 + (int)(Math.random()*23);
int num4 = 2 + (int)(Math.random()*23);

if(num1*num4 > num2*num3){
}

else if(num1*num4 < num2*num3){
}

System.out.println("The larger of " + num1 + "/" + num2 + " or " + num3 + "/" + num4 + " is");

System.out.println("Correct!");
correct++;
score += 5;
}
else{
System.out.println("Wrong!");
wrong++;
score -= 9;
}
amount--;
}```

This piece of my code determines whether a fraction is greater than another using cross multiplying. The user must decide which fraction is the larger value. In order to place "/" into the answer, I converted the "reply" and "answer" variables into Strings. However, the output comes out like so:
---------------------------------
The larger of 4/3 and 10/3 is
10/3
Wrong!
---------------------------------
I even tried adding - "System.out.println(answer); - and placed that exact answer into the line. But my answer was still wrong. Can anyone help me understand some more about Scanners, and how they work? I'm not quite sure why the program keeps returning "Wrong!" to me when I am clearly putting in the correct answer. Thanks in advance!

2. ## Re: Scanner Issues: Read for more detail, thanks.

I solved the issue by changing the "==" to .equals().

3. ## Re: Scanner Issues: Read for more detail, thanks.

Concatenating the empty Strings is an abuse of your powers.

4. ## Re: Scanner Issues: Read for more detail, thanks.

Originally Posted by Staticity
I solved the issue by changing the "==" to .equals().
This is a common error