Results 1 to 5 of 5
  1. #1
    darkbandit is offline Member
    Join Date
    Sep 2012
    Location
    Sherburne, NY
    Posts
    6
    Rep Power
    0

    Default 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.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    786
    Rep Power
    5

    Default 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)

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: New and got a question

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    philip1597 is offline Member
    Join Date
    Aug 2012
    Location
    New York
    Posts
    13
    Rep Power
    0

    Default 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 :)

  5. #5
    darkbandit is offline Member
    Join Date
    Sep 2012
    Location
    Sherburne, NY
    Posts
    6
    Rep Power
    0

    Default 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

  1. Replies: 2
    Last Post: 05-25-2012, 04:00 PM
  2. Java Question [Beginner Question]
    By joker760 in forum New To Java
    Replies: 3
    Last Post: 12-13-2011, 04:01 PM
  3. question posted by indissa: library question.
    By Fubarable in forum New To Java
    Replies: 2
    Last Post: 11-18-2011, 01:14 AM
  4. Question concerning question marks and colons
    By jim01 in forum New To Java
    Replies: 17
    Last Post: 01-14-2011, 12:05 AM
  5. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •