Results 1 to 9 of 9
- 02-05-2013, 02:42 AM #1
Member
- Join Date
- Feb 2013
- Posts
- 4
- Rep Power
- 0
New in Java silly question about input
I'm trying to run this program but I can't something in the input is wrong and I don't know what.
I JUST STARTED WITH JAVA 1 WEEK AGO. YES I'M A NOOB LOL
package ifstatement;
import java.util.Scanner;
public class exerciseclass {
/**
* @param args
*/
public static void main(String[] args) {
System.out.print("What is your age? ");
Scanner user = new Scanner(System.in);
System.out.println(user.nextLine());
if (user.nextLine() <=18){
System.out.println("User is 18 or younger");
}
else if (user.nextLine() > 18 && age < 40){
System.out.println("User is between 19 and 39");
}
else {
System.out.println("User is older than 40");
}
}
}
-
Re: New in Java silly question about input
- 02-05-2013, 02:46 AM #3
Member
- Join Date
- Feb 2013
- Posts
- 4
- Rep Power
- 0
Re: New in Java silly question about input
I just want to put an input for the user so the program checks if the user is under 18 years old, between 18 or 40 or over 40.
The program just gives me an error that something is not well typed and it doesn't work lol
-
Re: New in Java silly question about input
- 02-05-2013, 02:49 AM #5
Member
- Join Date
- Feb 2013
- Posts
- 4
- Rep Power
- 0
Re: New in Java silly question about input
Sorry:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Duplicate local variable user
at ifstatement.exerciseclass.main(exerciseclass.java: 19)
-
Re: New in Java silly question about input
You're trying to run code that doesn't compile -- never do this. Instead, first try to compile your class, and then report to us the compilation errors you see.
Edit, the error looks to be telling us that you are declaring the *same* variable. user, *twice*, the second time occurring on line 19. You should only declare this variable once.
edit: but I don't see this error in your code.
I suggest: try as I suggest, compile your program and report all errors here. Re-print your code here, but please use code tags (again see my signature link below). Please make sure that your code is well formatted with decent indentation so we can read it well. Then indicate by comment which line is causing the errors your getting.Last edited by Fubarable; 02-05-2013 at 02:55 AM.
- 02-05-2013, 03:07 AM #7
Member
- Join Date
- Feb 2013
- Posts
- 4
- Rep Power
- 0
Re: New in Java silly question about input
I'm sorry but I don't have very clear what you mean.
I tried to make some changes but I'm still doing something wrong and I don't know what :(
-
Re: New in Java silly question about input
Please tell us, what part of my requests above do you not understand?
Do you understand the difference between compiling and running a program? The .java code must first be compiled by the javac compiler to .class code, and then the class code is runnable. I'm asking you to compile your code and to show us any errors that the compiler is showing you. I'm asking you to post your latest code, the one that you've compiled most recently. I'm asking that you read my link in my signature links below on "how to use code tags" (or just click on the link here).
Most importantly, if anything we say or request confuses you, please ask for clarification. But also the more specific your request the better we can help.
- 02-05-2013, 05:09 AM #9
Re: New in Java silly question about input
Hector, in an attempt to aid Fubarable in explaining to you why he is asking of you what he is asking is for a few reasons and I will attempt to explain them in a very simple way.
If someone comes to you with a problem and only tells you that "it doesn't work", what would be your first reaction? First you must find out what the "it" is in that sentence. The next step you must take in that situation is understanding what it is supposed to do. Most of the time this can be done without doing more than simply looking at the object that is not working.
Unfortunately for us all, programming is not much like this at all. Without understanding where the programmer is coming from and what his desired goal is we have almost no idea on where to start. While some of the people here are very good at determining this, it is not always possible.
So what does this mean for you? This means you need to give us more information than we need, you want to give us more relevant information than you think we need. What is your input? What is your expected output? If you don't understand something, tell us what it is and how it confuses you. If its about an input from a scanner and you do not understand how a scanner input can be taken and used in your program you must tell us this.
If you don't understand why your syntax error is a syntax error, you must point us to your syntax error. If you do not know where your syntax error is then you must give us your compiler error. The full block of red text most compilers spit out when something has gone terribly wrong.
Today I ran into an issue that I was stumped on myself, my code compiled but I could not figure out why my code was acting up. So I dissected my code into focusing on the part where I was having an issue. My actual code is over 1,500 lines long currently and is no where near complete, but no one wants to sift through 1,500+ lines of code.
I suggest you read this website about the Short, Self Contained, Correct Example structure. It explains a lot of about how to properly ask people for help. Then I have linked my post from earlier which uses this model and is very thorough in my description of the issue which allowed me to receive help very quickly from site members. After reading the SSCCE website it may help to compare the site to how my post looks to see it a little more practical. Building a simple gui using arrays and loops.
It is okay to be new, we all have to start somewhere and everyone has walked in your shoes before. At one point in time each and every one of us had no idea what we were doing and had to learn by reading and then poking and prodding some code. Even posting a question online is a learning curve, and if you browse the forums you will find very many people do it wrong.
My final advice to you is to use your words, articulate descriptions will often prove to be more useful than a block of code. I know I just wrote you a term paper here, and I hope you took the time to read it and were able to understand it fully.- Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
- +Rep people for helpful posts.
Similar Threads
-
question on input in java?
By MW130 in forum New To JavaReplies: 9Last Post: 01-07-2013, 07:32 AM -
Silly boolean buttons
By dd2308 in forum New To JavaReplies: 8Last Post: 10-05-2012, 12:50 AM -
Silly strings
By MhilleXD in forum Advanced JavaReplies: 1Last Post: 10-02-2012, 10:32 AM -
Silly strings
By MhilleXD in forum JCreatorReplies: 1Last Post: 10-02-2012, 10:31 AM -
this is silly basic question in java . please help me make me clear
By coolforyou in forum New To JavaReplies: 5Last Post: 04-11-2012, 09:03 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks