Forums Register Login

please correct this code for me....

+Pie Number of slices to send: Send
**Please the code is supposed to output time in Hours, minutes and seconds when a value is entered into the prompt...please tell me what i am doing wrong in the code where there is an asterisk


import java.util.Scanner;

public class Person {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print("Please enter any number > ");
double time_Input = keyboard.nextDouble();
int numberOfHours = (int) time_Input / 60;
int numberOfMinutes = (int) (time_Input % 60);
double numberOfMinutes1 = time_Input % 60;
double numberOfSeconds = numberOfMinutes1 % numberOfMinutes ;
if (time_Input>0 && time_Input<999999999)
{
System.out.printf("Time is: %d Hours, %f Minutes, and %f Seconds", numberOfHours, numberOfMinutes1, numberOfSeconds); *****something is wrong here
}else {
System.out.println("NaN");
}


}

}
+Pie Number of slices to send: Send
Welcome to the Ranch!

You say "something is wrong". Can you explain in more detail what exactly is wrong?

Does the code compile, or do you get an error from the compiler?

If it compiles without errors, then what happens when you run it? Do you get an exception? If yes, then copy & paste the exact message from the exception.

If there's no exception, then does it produce some other output than what you expected? What exactly did you expect, what does it actually print and how is that different from what you expected?
+Pie Number of slices to send: Send
Hakim,

Learning process correctly formulate the question about the problem, usually is more important than the problem itself.
+Pie Number of slices to send: Send
"System.out.print("Please enter any number > "); "
Doesn't make any sense. isn't it? Read the question properly and try to solve it in a paper. You can identify your fault. It's a minor logic error. You can figure it out when you solve it in a white paper
+Pie Number of slices to send: Send
 

Jude Niroshan wrote:"System.out.print("Please enter any number > "); "
Doesn't make any sense. isn't it? Read the question properly and try to solve it in a paper. You can identify your fault. It's a minor logic error. You can figure it out when you solve it in a white paper



Jude, agree, it doesn't.
Still, no matter what he meant by writting "Please enter any number", OP's actual problem appears in his specified line.
+Pie Number of slices to send: Send
 

Liutauras Vilda wrote:
Still, no matter what he meant by writting "Please enter any number", OP's actual problem appears in his specified line.



Yes bro.. That's why i suggest him to solve it before coding. Cos he made a logic error when he calculates the seconds. 'OP's actual problem appears in his specified line', it's just a sysout. Nothing wrong there. What matters is here the values which he got for those variables. Isn't it?
+Pie Number of slices to send: Send
You're right, i didn't look at it carefully.
Wrong calculations.
+Pie Number of slices to send: Send
But without OP telling us the details, e.g. what did you expect to be printed? what was printed? how can we help?
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 545 times.
Similar Threads
Code help
Need help with structure...
I need help refining some code
download speed calculator
arithmetic
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:37:38.