Last active
August 29, 2015 13:56
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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