Seasonal display with Java switch

■ Normally, in order to use the fields of a class, it is necessary to instantiate the class using new, but the System class is instantiated when the program is started. Therefore, it can be used immediately (class variable) without instantiation.

import java.util.Scanner;

public class Season{

	public static void main(String[] args){
		System.out.println("Please enter an integer");

	    //The scanner next to the input stream new is the constructor
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		switch (a) {
			case 1 : case 2: case 12:
				System.out.println("It's winter");
				break;
			case 3 : case 4 : case 5:
				System.out.println("It's spring");
				break;
			case 6 : case 7: case 8:
				System.out.println("It's summer");
				break;
			case 9 : case 10: case 11:
				System.out.println("It's Autumn");
				break;
			default :
				System.out.println(a+"The moon does not exist");
			}

	    //Use the close method to destroy the instance and
	    //Free the used memory area.
		scan.close();

	}
}

■ A mistake that can still be made to forget the break.

Recommended Posts

Seasonal display with Java switch
Switch java with direnv
[Java] Branch enum with switch statement
[Android / Java] Switch events by display Fragment
Java switch statement
Easily switch Java versions with alias on macOS
Switch versions with alternatives after yum install java
Install java with Homebrew
Install Java with Ansible
Comfortable download with JAVA
Download Java with Ansible
Let's scrape with Java! !!
Build Java with Wercker
Endian conversion with JAVA
Display characters on I2C 1602 LCD with Raspberry Pi 3 & Java
Easy BDD with (Java) Spectrum?
Use Lambda Layers with Java
Getting Started with Java Collection
Java Config with Spring MVC
Basic Authentication with Java 11 HttpClient
Let's experiment with Java inlining
Run batch with docker-compose with Java batch
[Template] MySQL connection with Java
Rewrite Java try-catch with Optional
Install Java 7 with Homebrew (cask)
[Java] JSON communication with jackson
Java to play with Function
Try DB connection with Java
Enable Java EE with NetBeans 9
[Java] JavaConfig with Static InnerClass
Try gRPC with Java, Maven
Let's operate Excel with Java! !!
Version control Java with SDKMAN
Java if and switch statements
RSA encryption / decryption with java 8
Paging PDF with Java + PDFBox.jar
Sort strings functionally with java
Object-oriented (java) with Strike Gundam
[Java] How to display Wingdings
[Java] Content acquisition with HttpCliient
Java version control with jenv
Troubleshooting with Java Flight Recorder
Streamline Java testing with Spock
Connect to DB with Java
Connect to MySQL 8 with Java
Using Mapper with Java (Spring)
Java study memo 2 with Progate
Getting Started with Java Basics
Use SpatiaLite with Java / JDBC
Study Java with Progate Note 1
Compare Java 8 Optional with Swift
HTML parsing with JAVA (scraping)
Run Java VM with WebAssembly
Screen transition with swing, java
Java unit tests with Mockito
How to switch Java version with direnv in terminal on Mac
Let's create a TODO application in Java 5 Switch the display of TODO
[Java 8] Duplicate deletion (& duplicate check) with Stream
Create an immutable class with JAVA
Java lambda expressions learned with Comparator
New grammar for Java 12 Switch statements