hello I am new to the forum and to java and i have a program that the user inputs the time followed by am and pm and the program changes it to military time. at the end the program asks if you want to rerun the program. the program works when i enter no but i cant figure out how to get it to work if the user enters yes. also if the time is am the military time is the same as the input except there is a 0 in front. i cant figure out how to output the 0. +0 wont work i have added my code below!
import java.util.*; public class Time{ public static void main(String [ ] args) { Scanner input=new Scanner(System.in); int hour, minute; int hour24,change; String ampm,answer; boolean yes=true; boolean no=false; System.out.println("Enter the time followed by am or pm, and I will convert:"); hour= input.nextInt(); minute=input.nextInt(); ampm=input.next(); while (yes){ hour24 = Time.convertHour(hour, ampm); print_time(hour24, minute); System.out.println("The time is: " +hour24 + ":" +minute); System.out.println("Would you like to run again? Yes Or No"); answer=input.next(); if (answer.equals("yes")) { System.out.println("Please enter time followed by am or pm:"); yes=true; } else if(answer.equals("no")) yes=false; //break; } } public static int convertHour(int hours_12, String am_pm){ if(hours_12==12 && am_pm.equals("am")) hours_12=( hours_12-12); else if(hours_12<=11 && am_pm.equals("am")) hours_12=(hours_12); else if (hours_12<=11 && am_pm.equals("pm")) hours_12=hours_12+12; return hours_12; // <--------- I added this return statement } public static void print_time(int hours_24, int mintues) { System.out.println(hours_24+ ":" +mintues) ; } }