Results 1 to 5 of 5
Thread: New and got a question
- 09-16-2012, 05:25 PM #1
Member
- Join Date
- Sep 2012
- Location
- Sherburne, NY
- Posts
- 6
- Rep Power
- 0
New and got a question
First of all I just started learning Java on my own last Wensday. I am using the book think java how to think like a computer scientist(at least i think that is the name), and using eclispe for a compiler
well i got to one of the exercises and it says to create variable named day date, month and year. than to print them on screen. so this is the code i got
public class TwoPointFour {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String Day;
String Month;
int Date, Year;
Day = Sunday;
Month = September;
Date = 16;
Year = 2012;
System.out.println(Day);
System.out.println(Date);
System.out.println(Month);
System.out.println(Year);
but it gives me two errors
Sunday cannot be resolved to a variable and it says the same thing for september.
and yes i have done some research that gives a better way, where you dont use those variables.
but i want to know what am i doing wrong and why that error message keep popping up.
- 09-16-2012, 06:26 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Re: New and got a question
Day and Month (take a look at Java`s Naming Conventions) are Strings!
->
Day = "Sunday"
String (Java Platform SE 6)
- 09-16-2012, 06:57 PM #3
Re: New and got a question
Forum Rules -- particularly the third paragraph
Guide For New Members
BB Code List - Java Programming Forum
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 09-17-2012, 04:19 AM #4
Member
- Join Date
- Aug 2012
- Location
- New York
- Posts
- 13
- Rep Power
- 0
Re: New and got a question
First of all use the code formatting it makes it easier to read. To answer your question, well its cause sunday and september are not assigned. They should not be variables, variables usually need to change but something as specific as september or sunday should be a string assigned to Day and Month.
P.S. Good Luck on teaching yourself I'm doing it too :)
- 09-22-2012, 01:30 AM #5
Member
- Join Date
- Sep 2012
- Location
- Sherburne, NY
- Posts
- 6
- Rep Power
- 0
Re: New and got a question
thanks to all three of you after i read the first repose i face palmed. and than proceeded to go back and re read the chapters of think java and watch some videos. man trying to learn java or any programming language can be a challenge, but i accept this challenge hopefully no more simple mistakes like that.
oh and i am reading the links provided thanks again
Similar Threads
-
Forum question on why discussion threads are locked though question is unanswered
By pseeburger in forum Suggestions & FeedbackReplies: 2Last Post: 05-25-2012, 04:00 PM -
Java Question [Beginner Question]
By joker760 in forum New To JavaReplies: 3Last Post: 12-13-2011, 04:01 PM -
question posted by indissa: library question.
By Fubarable in forum New To JavaReplies: 2Last Post: 11-18-2011, 01:14 AM -
Question concerning question marks and colons
By jim01 in forum New To JavaReplies: 17Last Post: 01-14-2011, 12:05 AM -
Question mark colon operator question
By orchid in forum Advanced JavaReplies: 9Last Post: 12-19-2010, 08:49 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks