Login    Register
User Information
Username:
Password:
We are a free and open
community, all are welcome.
Click here to Register
Sponsored
Who is online

In total there are 74 users online :: 7 registered, 0 hidden and 67 guests


Most users ever online was 218 on Wed Dec 07, 2016 6:58 pm

Registered users: Bing [Bot], Exabot [Bot], Google [Bot], Google Adsense [Bot], Majestic-12 [Bot], MSNbot Media, Yahoo [Bot] based on users active over the past 5 minutes

The Team
Administrators
Global Moderators
global_moderators.png CS

who knows java?

All non-spudgun related discussion goes here such as projects, theories, serious questions, etc. All "off-topic" posts (aka useless posting, determined by moderators) will be removed.
Sponsored 
  • Author
    Message

who knows java?

Unread postAuthor: Carlman » Thu Mar 13, 2008 6:41 am

Hey all,

i need some help with someone who knows a bit of java. Ive just started it in uni and having trouble getting a program to compile.

I need to make a program that can display 4220 seconds as hours:minutes:seconds and then skip a line then do the same for 2500seconds.

heres what i have so far:

/**
* Converts two different number of seconds to hours:minutes:seconds.
*
*/
public class TimeChanger
{
public static void main(String[] args)
{
int time = 4220;
int hours = time / 3600;
int hoursRemainder = time % 3600;
int minutes = hoursRemainder / 60;
int minutesRemainder = hoursRemainder % 60;
int seconds = minutesRemainder;
System.out.println(“4220 seconds:" +hours ":" +minutes ":" +seconds);

int time = 2500;
int hours = time / 3600;
int hoursRemainder = time % 3600;
int minutes = hoursRemainder / 60;
int minutesRemainder = hoursRemainder % 60;
int seconds = minutesRemainder;
System.out.println(“4220 seconds:" +hours ":" +minutes ":" +seconds);
}

}

im using blueJ as my editing tool and its coming up with an illegal character on the first print line.

any help would be much appreciated
  • 0

Last edited by Carlman on Wed Mar 19, 2008 8:52 am, edited 1 time in total.
Image
Aussie spudders unite!!
User avatar
Carlman
Major General
Major General
 
Posts: 1618
Joined: Sat Nov 24, 2007 1:18 am
Location: Western Australia
Reputation: 0

Unread postAuthor: Carlman » Thu Mar 13, 2008 9:35 am

public class TimeChanger
{
public static void main(String[] args)
{
int time = 4220;
int hours = time / 3600;
int hoursRemainder = time % 3600;
int minutes = hoursRemainder / 60;
int minutesRemainder = hoursRemainder % 60;
int seconds = minutesRemainder;
System.out.println("4220 seconds: " +hours +":" +minutes +":" +seconds);

time = 2500;
hours = time / 3600;
hoursRemainder = time % 3600;
minutes = hoursRemainder / 60;
minutesRemainder = hoursRemainder % 60;
seconds = minutesRemainder;
System.out.println("2500 seconds: " +hours +":" +minutes +":" +seconds);
}

}

its all good i sorted it out in the end!

thanks to all who helped :roll: lol jokes :D
  • 0

Image
Aussie spudders unite!!
User avatar
Carlman
Major General
Major General
 
Posts: 1618
Joined: Sat Nov 24, 2007 1:18 am
Location: Western Australia
Reputation: 0

Unread postAuthor: dewey-1 » Thu Mar 13, 2008 10:19 am

--
  • 0

Last edited by dewey-1 on Sun Apr 20, 2008 1:04 pm, edited 1 time in total.
User avatar
dewey-1
Major General
Major General
 
Posts: 1298
Joined: Wed Mar 28, 2007 10:24 am
Location: NE Wisconsin USA
Reputation: 0

Unread postAuthor: jimmy101 » Thu Mar 13, 2008 11:02 am

So what was the error? The "smart quotes" in the println statements?
  • 0

Image

jimmy101
Lieutenant General
Lieutenant General
 
Posts: 3130
Joined: Wed Mar 28, 2007 9:48 am
Location: Greenwood, Indiana
Country: United States (us)
Reputation: 7

Unread postAuthor: keep_it_real » Thu Mar 13, 2008 11:08 am

he just forgot a plus sign after hours and minutes.
  • 0


keep_it_real
Captain
Captain
 
Posts: 320
Joined: Sat Dec 23, 2006 4:41 pm
Location: Bend, Oregon
Reputation: 0

Unread postAuthor: LikimysCrotchus5 » Thu Mar 13, 2008 2:02 pm

This aint too hard, im doing if, while and for loops and i dont understand for loops too much but if and while arent really hard.

Now i know i can come to someone here if i need help :)
  • 0

4SPC, My 4" piston 3" porting cannon
Memo:
Fix up copper cannon
Fix up 4SPC
Start Stirrup pump
Start Toolies piston bazooka
User avatar
LikimysCrotchus5
Brigadier General
Brigadier General
 
Posts: 1100
Joined: Tue Sep 04, 2007 10:16 pm
Reputation: 0

Unread postAuthor: Carlman » Thu Mar 13, 2008 5:25 pm

yea the prob was i was defining the variables again which it didnt like and i foot to add the other parts of the string.

@ LikimysCrotchus5: I start loops today :D
  • 0

Image
Aussie spudders unite!!
User avatar
Carlman
Major General
Major General
 
Posts: 1618
Joined: Sat Nov 24, 2007 1:18 am
Location: Western Australia
Reputation: 0

Sponsored

Sponsor
 


Unread postAuthor: LikimysCrotchus5 » Thu Mar 13, 2008 5:42 pm

Well if you dont understand something, and i do, then give me a pm. We had the option of downloading jgrasp (java system and compiler i use) and i did so i can get some work done for school and also make programs to do math for me.

For example, i made a pythagorean theorem calculator that outputs the third side, instead of typing in a calculator. So it makes some work easier.

So if you want some programs for the hell of it, ill give you all the code.

P.S. For the keyboard reader, i usually give it a name besides reader, like Joe, makes programming sort of more fun :D
  • 0

4SPC, My 4" piston 3" porting cannon
Memo:
Fix up copper cannon
Fix up 4SPC
Start Stirrup pump
Start Toolies piston bazooka
User avatar
LikimysCrotchus5
Brigadier General
Brigadier General
 
Posts: 1100
Joined: Tue Sep 04, 2007 10:16 pm
Reputation: 0

Unread postAuthor: Carlman » Thu Mar 13, 2008 11:18 pm

how far along are you in java LMC?

ive had about 3 lectures on it :D

i use BlueJ, it was developed by a university in the eastern states of aussie land and is sponsored by sun microsystems. Its basically an easy to use system and compiler.
yea thanks foe the offer of help might take you up on it later :wink:
  • 0

Image
Aussie spudders unite!!
User avatar
Carlman
Major General
Major General
 
Posts: 1618
Joined: Sat Nov 24, 2007 1:18 am
Location: Western Australia
Reputation: 0

Unread postAuthor: LikimysCrotchus5 » Fri Mar 14, 2008 12:07 am

Well i started this class in the beginning of my second semester so i have had almost 2 months i think.

I have this class for a semester so the farthest our teacher said we would get is to applets, which are like little internet advertizmetns, i think.

Yea and feel free to do pm me whenever, and your welcome :)
  • 0

4SPC, My 4" piston 3" porting cannon
Memo:
Fix up copper cannon
Fix up 4SPC
Start Stirrup pump
Start Toolies piston bazooka
User avatar
LikimysCrotchus5
Brigadier General
Brigadier General
 
Posts: 1100
Joined: Tue Sep 04, 2007 10:16 pm
Reputation: 0

Return to Non-Spudgun Related Discussion

Who is online

Registered users: Bing [Bot], Exabot [Bot], Google [Bot], Google Adsense [Bot], Majestic-12 [Bot], MSNbot Media, Yahoo [Bot]

Reputation System ©'