• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

long - int problem

 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am practicing collections but stuck on very fundamental thing .

i made a class person ,in which a a variable -contactnum is of int type.

when i initialize its object ,as Person p1=new Person("abc",12,1234567890);
It says error ,as int cant take such long values ,
Then if i change datatype & all related datatypes(in contructor/methods) to long ,even then it says same error :int is out of range.
so finally i had to crop the passed data f lesser value :like ("abc",12,1234567);

But in real life ,how would i make it handle long values .

My class person is ::

class Person{
String name ;
int age;
long contactno;
Person(String n ,int a ,long c)
{
name=n; age=a;contactno=c;
}
public String toString(){
return(name+" "+age+" yrs old with ,Can be reached at " + contactno);
}
}





Thnx a lot ,
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The compiler needs to be told that large literals are of type long. To do this, append a L to the end:
 
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic