Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // -------------------------------------------------------
- // Assignment 2
- // Written by: Kewen Liang - 40129628
- // For COMP 248 Section EC – Fall 2019
- // -------------------------------------------------------
- //Question 1. Converting an integer (1-12) to the appropriate Persian month using if/else statements.
- import java.util.Scanner;
- public class Assign2Q1ifelse {
- public static void main(String[] args) {
- //Store months into arrays for easy use.
- String[] months = {"Farvardin", "Ordibehesht", "Khordad", "Tir", "Mordad", "Shahrivar", "Mehr", "Aban", "Azar", "Dey", "Bahman", "Esfand"};
- //String[] seasons = {"Keep warm Yourself in Winter", "Happy Spring", "Have Fun in Summer", "Ready For Fall"};
- String season = "";
- int monthnumber;
- Scanner input = new Scanner(System.in);
- System.out.print("Please enter the Month as a number 1-12: ");
- monthnumber = input.nextInt();
- //exits if month is < 1 or > 12
- if (monthnumber < 1 || monthnumber > 12)
- {
- System.out.println("Sorry, " + monthnumber + " is not a valid month.");
- input.close();
- return;
- }
- //determine season with if/ else :)
- if (monthnumber >= 1 && monthnumber < 4)
- season = ", Happy Spring";
- else if (monthnumber >= 4 && monthnumber < 7)
- season = ", Have Fun in Summer";
- else if (monthnumber >= 7 && monthnumber < 10)
- season = ", Ready For Fall";
- else if (monthnumber >= 10 && monthnumber <= 12)
- season = ", Keep warm Yourself in Winter";
- //find month by applying -1 to input
- System.out.println("We are in " + months[monthnumber-1] + season);
- input.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement