Results 1 to 7 of 7
Thread: java return help
- 02-14-2009, 07:54 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 2
- Rep Power
- 0
- 02-14-2009, 08:39 PM #2
Member
- Join Date
- Feb 2009
- Posts
- 48
- Rep Power
- 0
i can do this in c++.. i cant tell you how to do it in java.
int year;
int age;
cout<<What year were you?<<endl;
cin>>year;
if ((year>=1960) && (year<=2000))
{
cout<<you are this old=;
cout<<2009-year<<endl;
}
its not perfect but thats how it will look.. the if statement will work in java
- 02-14-2009, 09:37 PM #3
How are they to enter the code?
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 02-15-2009, 12:40 AM #4
pseudocode
Java Code:public return_data_type getAge(data_type birthYear){ currentYear = 2009; // look into calendar class. age = currentYear - birthYear; return age; }USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 02-15-2009, 06:12 AM #5
Member
- Join Date
- Feb 2009
- Posts
- 48
- Rep Power
- 0
hope we could help man..
and sorry i cant help to much with java code.. all ive ever learned was applets. c++ i can do it ; ]
good luck brah.
-
Sounds too much like homework here. What you have you done yourself to solve this?
- 02-15-2009, 06:23 AM #7
Member
- Join Date
- Feb 2009
- Posts
- 7
- Rep Power
- 0
public int getAge(int cage)
{
Date d=new Date();
int cryear=d.getYear()+1900;
return (cryear-cage);
}
This will work fine ,it will work for any year,don't hard code the current year ,this is not good practice ,u can put the condition to check birth year is in between 1960-2000 ok.
this will work fine for who born after 1900 only.
Thank you
Similar Threads
-
Java Native Access (JNA) return types of void *
By burnumd in forum Advanced JavaReplies: 5Last Post: 01-15-2010, 12:09 AM -
Using int/int, 7/5 would return 1
By zoe in forum New To JavaReplies: 2Last Post: 12-02-2008, 11:25 AM -
about 'return'.
By helloworld in forum New To JavaReplies: 9Last Post: 11-28-2008, 04:08 AM -
if..else..return
By mqdias in forum New To JavaReplies: 1Last Post: 08-10-2007, 04:20 PM -
Return value of method
By cachi in forum New To JavaReplies: 1Last Post: 08-01-2007, 08:23 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks