Skip to content

Instantly share code, notes, and snippets.

@itsJarrett
Created June 4, 2015 22:44
Show Gist options
  • Save itsJarrett/7031c40de63c30bf9ace to your computer and use it in GitHub Desktop.
Save itsJarrett/7031c40de63c30bf9ace to your computer and use it in GitHub Desktop.
Month to year(s) converter!
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
monthToYears();
}
public static void monthToYears() {
Scanner s = new Scanner(System.in);
System.out.println("Enter amount of months you want to convert to years.");
int months = s.nextInt();
int years = months / 12;
months = months % 12;
if (months != 0) {
System.out.println("That converts to " + years + " year(s)" + " and " + months + " month(s).");
} else {
System.out.println("That converts to " + years + " year(s).");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment