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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: What's wrong with my code?

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default What's wrong with my code?

    class DataTypes {

    public static void main(String[] args) {
    char letter = 'M';
    String title = "Java In Easy Steps";
    int num = 365;
    float decimal = 98.6f;
    boolean result = true;
    System.out.println("Initial is" + letter);
    System.out.println("Book is" + title);
    System.out.println("Days are" + number);
    System.out.println("Temperature is" + decimal);
    System.out.println("Answer is" + result);

    }

    }

    This is the error I get below...

    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    number cannot be resolved to a variable

    at DataTypes.main(DataTypes.java:12)


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: What's wrong with my code?

    The variable 'number' is unknown. Did you mean 'num'?

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: What's wrong with my code?

    Thanks. I did the num thing. I got it right, but how do I get things not to run into each other? There should be a space between answers. Everything is stuck together. Thanks again.

    Initial isM
    Book isJava In Easy Steps
    Days are365
    Temperature is98.6
    Answer istrue

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: What's wrong with my code?

    You have to manually add a space where you want one
    if:
    System.out.println("Initial is" + letter);
    gives:
    Initial isM
    ...how did you get a space between 'Initial' and 'is'?

Similar Threads

  1. What's Wrong With My Code?
    By markchua in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 15th, 2013, 03:20 AM
  2. what is wrong with my code? please help
    By black.angel in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 13th, 2012, 02:34 PM
  3. can someone tell me what's wrong with my code
    By Nate08 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 23rd, 2012, 05:07 PM
  4. what's wrong with this code
    By gcsekhar in forum Java Networking
    Replies: 5
    Last Post: July 21st, 2011, 06:01 AM
  5. want wrong with my code
    By drum in forum Member Introductions
    Replies: 1
    Last Post: May 20th, 2011, 09:06 AM