Originally Posted by
sireesha
which is usefull(commonly used) way to represent numbers like
int x,y;
or
Integer x,y;
what is the difference between them ?
i wrote code like
class test4
{
public static void main(String args[])
{
Integer x,y;
x=23;
y=30;
System.out.println(x+ys);
}
}
i got following errors
1.incompatible types
2. operator + cannot be applied to java.lang.Integer,java.lang.Integer.
what is wrong with my code ?
please tell me..
Well, you have declared x and y as type "Integer". Integer is a class and when you make such declarations you are creating objects of that class. As such you cannot use the assignment operator to assign them values of type "int", and also you cannot apply the "+" operator to them. In order to use x and y, you need to call the methods of the class Integer.
I think what you want to do is this:
class test4
{
public static void main(String args[])
{
int x,y;
x=23;
y=30;
System.out.println(x+y);
}
}
HTH