#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Help with "alarm clock" code

ArizonaMember Posts: 3

Hello, thanks for any help, I am SUPER new and I'm having a hard time with this. I post the question and then my code. I'm having a hard time trying to figure out how to get the am / pm working. Also, can you tell me what's wrong with my if and else statements.

Here is the assignment:
Many people keep time using a 24-hour clock (11 is 11am and 23 is 11pm, 0 is midnight). If it is currently 13 and you set your alarm to go off in 50 hours, then it will go off at 3 PM. Write a Java program to solve the general version of the above problem. Ask the user for the time now (in hours), and then ask for the number of hours to wait for the alarm. Your program should output what the time would be on the clock (in 12- hour AM/PM format) when the alarm goes off.

Here is my code so far:

import java.util.Scanner;

public class Alarm
{
public static void main(String[] args)
{

``````int currentTime;
int waitingTime;
int hours;
int timeOfDay;

Scanner scan = new Scanner(System.in);

System.out.print("Please enter the current time (in hours): ");
currentTime = scan.nextInt();

System.out.print("Please enter the number of hours to wait for the alarm: ");
waitingTime = scan.nextInt();

hours = (currentTime + waitingTime);

timeOfDay = (hours % 24);

if (currentTime > 12)
System.out.print("am");
else
System.out.print("pm");

System.out.println("The alarm would go off at: " + timeOfDay);

}
``````

}