newbie with some questions =]

Hello all! I'm very new to Java and am just getting used to it.

First off, how long does it usually take/did it take you to get certified? .*)

Secondly, I have this code that converts seconds to hours, minutes, seconds.

I have two problems I'm hoping one of you JavaGods can help me out with:

1.) How would you format it so the output is on one line ie., 23:05:10

2.) How do you change the data type, if that's what it is so I can input a lot of seconds. I'm not quite sure how many but if I input too many integers I get this error message:

java.util.InputMismatchException: For input string: "34543543535"

at java.util.Scanner.nextInt(Scanner.java:2097)

at java.util.Scanner.nextInt(Scanner.java:2050)

at MakeTime.main(MakeTime.java:17)

java.util.InputMismatchException: For input string: "34534545345"

at java.util.Scanner.nextInt(Scanner.java:2097)

at java.util.Scanner.nextInt(Scanner.java:2050)

at MakeTime.main(MakeTime.java:17)

or I'll get:

InputMismatchException:

For input string: "34534545345" (in java.util.Scanner)

__

Here's my code:

import java.util.*;

publicclass MakeTime

{

static Scanner console =new Scanner(System.in);

staticfinalint HOURS = 3600;

staticfinalint MINUTES = 60;

publicstaticvoid main(String[] args)

{

int time;

System.out.print("Enter the time in seconds: ");

System.out.flush();

time = console.nextInt();

System.out.println();

System.out.println("Hours: " + time / HOURS);

time = time % HOURS;

System.out.println("Minutes: " + time / MINUTES);

time = time % MINUTES;

System.out.println ("Seconds: " + time);

}

}

Perhaps, I should've put this thread in the "New to Java" forum. =]

[2576 byte] By [nsfoura] at [2007-11-27 2:07:48]
# 1

> First off, how long does it usually take to get

> certified? .*)

Depends on the individual.

> Secondly, I have this code that converts seconds to

> hours, minutes, seconds.

>

> I have two problems I'm hoping one of you JavaGods

> can help me out with:

> 1.) How would you format it so the output is on one

> line ie., 23:05:10

One would use the SimpleDateFormat class on a Date object, possibly taken from an Calendar instance.

> 2.) How do you change the data type, if that's what

> it is so I can input a lot of seconds. I'm not quite

> sure how many but if I input too many integers I get

> this error message:

Maybe you shouldn't use "nextInt" but "nextLong"? Consider reading the documentation of the classes you use.

CeciNEstPasUnProgrammeura at 2007-7-12 1:56:25 > top of Java-index,Java Essentials,Java Programming...
# 2
The maximum value an int can hold is: 2147483647 (== (2^31)-1). Tr using a long instead, which can hold (2^63)-1.
prometheuzza at 2007-7-12 1:56:25 > top of Java-index,Java Essentials,Java Programming...
# 3
removed, answered beforeMessage was edited by: PhHein
PhHeina at 2007-7-12 1:56:25 > top of Java-index,Java Essentials,Java Programming...
# 4

Reference

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html

The int data type is a 32-bit signed two's complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive).

Obviously, 34543543535 greater than 2147483647. You would have a problem.

You should either input a smaller number or use long instead.

rym82a at 2007-7-12 1:56:25 > top of Java-index,Java Essentials,Java Programming...
# 5
thanks everyone for the help and warm welcome!
nsfoura at 2007-7-12 1:56:25 > top of Java-index,Java Essentials,Java Programming...