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 2 of 2

Thread: Adding two byte/ short variables

  1. #1
    Member
    Join Date
    Jan 2012
    Location
    Hyderabad, Andhra Pradesh, India
    Posts
    32
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Adding two byte/ short variables

    public class srgf {
     
     public static void main(String args[])
     {
     	short a =1;
            short b=1;
     	short c=a+b;
     	System.out.println(c);
     }
     
    }
    Why does this code generate a 'possible loss of precision error' during compilation?


  2. #2
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: Adding two byte/ short variables

    Quote Originally Posted by ranjithfs1 View Post
    public class srgf {
     
     public static void main(String args[])
     {
     	short a =1;
            short b=1;
     	short c=a+b;
     	System.out.println(c);
     }
     
    }
    Why does this code generate a 'possible loss of precision error' during compilation?
    Hello ranjithfs1!
    I googled problem with shorts adding java and the first result was this interesting thread.
    Read it and you will probably understand what's going on with the compiler complains. If not, come back with the questions you have.
    Hope this helps.

Similar Threads

  1. Differences between local variables and instance variables
    By rob17 in forum Java Theory & Questions
    Replies: 2
    Last Post: March 6th, 2012, 08:34 PM
  2. Instance Variables and local variables difference
    By dcwang3 in forum Java Theory & Questions
    Replies: 3
    Last Post: October 31st, 2011, 06:33 AM
  3. short survey comparing netbeans and eclipse for my dissertation
    By jeremylaks in forum Java Theory & Questions
    Replies: 0
    Last Post: April 2nd, 2011, 11:09 AM
  4. way too hard to explain this in short. please help guys!!
    By humdinger in forum Collections and Generics
    Replies: 4
    Last Post: March 15th, 2010, 05:57 AM
  5. Short java project
    By derky in forum Paid Java Projects
    Replies: 3
    Last Post: October 28th, 2009, 09:48 PM