SRL Archive - Java Help and Tutorials

How can i make this easy code?


Gaston7eze

2012-01-12 17:40:09

Well actually im trying to make the User to input the answer of this simple problem.
But,if the user input bad the answer it will ask again.I dont know what i am doing bad.

Code:

import java.util.Scanner;

import java.util.Scanner;


public class Guys {
public static void main(String []args){
Scanner Hello=new Scanner(System.in);
int SPrimerNum=50;
int SegundoNum=50;
long R;
System.out.println("How much is 50+50?");
R=Gaston.nextLong();
if (R=100){
System.out.println("You do it pretty well:)");
}else{
System.out.println("Incorrect");

}
}


}

}
}
It says me that it cannot convert from long to a boolean.
Help please.

PatDuffy

2012-01-12 17:44:07

Why not store R as an integer since it's 100?

I'm also new to JAVA, taking a basic course at my HS this year.

Gaston7eze

2012-01-12 17:45:58

From: PatDuffy
Why not store R as an integer since it's 100?

I'm also new to JAVA, taking a basic course at my HS this year.


Nice!
Im trying to learn throw the internet but it´s too difficult.I have that problem and other that i speak Spanish instead of English.Good luck learning Java.Im gonna see if the tip works.Thanks!

Edit:Same error but now it says :"Cannot convert int to boolean " :S

Richard

2012-01-12 18:13:08

I'm confused as to what Gaston is an instance of?

Anyway, it looks like you're trying to use the assign a value to R rather than comparing it, you'll need to use == when you are comparing in Java, that way it will output a boolean value.

Gaston7eze

2012-01-12 18:19:11

Ohh,it worked.I did know that but i forgot it.LOL.Thanks Richard!