-
-
Save Angel-Rojas/622137fcd4ee94bbeae6 to your computer and use it in GitHub Desktop.
/* | |
* This program prints the seasons | |
* | |
* @author Angel Rojas | |
* Course: COMP B11 | |
* Created: Sep 25, 2014 | |
* Source File: Seasons.java | |
*/ | |
import java.util.Scanner; | |
public class Seasons { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); // set up our Input take-in Scanner. | |
String season = "Your unchanged season."; // Edit: This will print if invalid # is passed. | |
// user enters month and day | |
System.out.println("Please enter Month followed by Day"); | |
int month = in.nextInt(); | |
int day = in.nextInt(); | |
// checks month and day! | |
if (month <= 3) { | |
season = "Winter"; | |
} else if (month == 4 || month == 5 || month == 6) { | |
season = "Spring"; | |
} else if (month == 7 || month == 8 || month == 9) { | |
season = "Summer"; | |
} else if (month == 10 || month == 11 || month == 12) { | |
season = "Fall"; | |
} | |
if (month % 3 == 0 && day >= 21) { | |
if (season.equals("Winter")) { | |
season = "Spring"; | |
} else if (season.equals("Spring")) { | |
season = "Summer"; | |
} else if (season.equals("Summer")) { | |
season = "Fall"; | |
} else | |
season = "Winter"; | |
} | |
System.out.print(season); | |
in.close(); // close out our Input reader | |
} | |
} |
Thanks Pat. What did I do wrong? I used the copy url button, but it didn't paste correctly. Should I have used the embed url button?
Oh, you're right! Can't believe i had initialized those and never even used them. MMk thanks for the input guys! Making said changes now.
So why does our String season have to be set to a blank "" str? can you guys maybe explain that. Thanks again (: EDIT: Code is running smoothly :) so much better than when i originally wrote this back in 2014 aha. Thanks guys for all the help, much appreciated!
@ChadH1971 You used the clone URL, which is what you would use if you wanted to copy the Gist to your computer using a Git client. To share the page, just copy the URL from your browser like you would for any other webpage.
Here is @ChadH1971's code: https://gist.github.com/ChadH1971/690d17d52c2a2181bee5