• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

New to Java and wanting to learn

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Needed help getting a compiler error



new to java, error is

"int cannot be dereferenced" i know its because im trying to display an int as a string but i know theirs a way just need help
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
age is an int variable, a primitive and you can't call a method on a primitive. Since String is smart enough to figure out what to do here, why not simply do:

 
Kamran Khaen
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
bessically, in my assignment ive been asked to add a toString method, which includes the student id, name , age and points. Now the error is saying im "missing a return statement".

and would this method be ok as a toString method or do i have to carry out different codeing?
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
toString() method looks OK. You need to return your String at last because return type of method is String..

public String toString()
{
String StudentInfo = "Student ID: " + idNumber +
"\nName: " + name +
"\nPoints: " + achievementPts +
"\nAge: " + age;
return StudentInfo;
}

well, Welcome to java ranch..You will enjoy java here
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please do not post in all uppercase. Please read this for more information. I have adjusted to topic title for you.
 
Kamran Khaen
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Siddhesh Deodhar wrote:toString() method looks OK. You need to return your String at last because return type of method is String..

public String toString()
{
String StudentInfo = "Student ID: " + idNumber +
"\nName: " + name +
"\nPoints: " + achievementPts +
"\nAge: " + age;
return StudentInfo;
}

well, Welcome to java ranch..You will enjoy java here





fanks it worked, just wondering is the to string method spost to print to terminal window?
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"j Blue", please check your private messages for an important administrative matter.
 
Sheriff
Posts: 22796
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Beginning Java. And please use a meaningful subject line next time.
 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic