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: Question!

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

    Default Question!

    Hi what does this mean 5 + '7' + 2, i am pretty new to all this so please be patient with me, i write it down in the interactions window, and get 62. So far i know its some kind of math question, but what does it mean to write something in " ' ' "


  2. #2
    Member
    Join Date
    Sep 2013
    Posts
    70
    Thanks
    1
    Thanked 13 Times in 13 Posts

    Default Re: Question!

    When something is encased in '' it defines it as character.
    Something encased in " " defines it as a string.

    char someChar = 'b'; // Can only contain a single character
    String someString = "This is a string"; // A string is just a collection of chars

    I hadn't seen an equation like that but if I were to guess why it works is that the compiler is taking the dec value of the char and adding it into the equation. So it probably does 5 + value of char + 2. Someone with more experience will chime in and explain it better.

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

    Default Re: Question!

    Quote Originally Posted by Ubiquitous View Post
    So it probably does 5 + value of char + 2.

  4. #4
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default Re: Question!

    Hello.
    If a character say c is enclosed in single quotes as 'c' then the expression 'c' returns the ASCII code of the character c.
    So in your expression 5+'7'+2, three values are added: 5, ascii value of 7 which is 55, and 2.
    So the sum comes to 62.

    Syed.