Skip to content

Instantly share code, notes, and snippets.

@JorgeOlvera
Last active August 29, 2015 13:56
Show Gist options
  • Save JorgeOlvera/8968291 to your computer and use it in GitHub Desktop.
Save JorgeOlvera/8968291 to your computer and use it in GitHub Desktop.
Given a number from 1 to 12, the program returns the corresponding month
//Givenanumberfrom1-12,returnthenameoftheappropriatemonth.
import java.util.Scanner;
public class months {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int onetotwelve = input.nextInt();
if (onetotwelve > 1 || onetotwelve < 12){
String nameOfMonth = monthNames(onetotwelve);
System.out.println(nameOfMonth);
}
else {
System.out.println("Please introduce a number from 1 to 12");
}
}
public static String monthNames(int onetotwelve) {
String[] months = {"January", "February", "March", "April", "May","June","July","August","September","October","November","December"};
int monthnumber= onetotwelve-1;
String a = months[monthnumber];
return a;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment