I tried to display the calendar on the Eclipse console using Java.

Just for notes. ・ When cal.set (int year, int month-1,1), it was easy to forget that the month was set from "0 to 11" ⇒ "January to December". -You can find out how many days there are in xx month of xxxx by cal.getActualMaximum (Calendar.DATE). -The days of the week and dates are stored using an array.

image.png

・ A class that creates and outputs a calendar   package foo; import java.util.Calendar; public class Calmaker {

public void Makecal(int year,int month){
Calendar cal = Calendar.getInstance();
//int weekday = cal.get(Calendar.DAY_OF_WEEK);
//System.out.println(weekday);

int days[][] = new int[6][7];

System.out.println ("Sun Mon Tue Wed Thu Fri Sat"); int row = 0;

//一日から最終日までループ for (int i = 1; i <= cal.getActualMaximum(Calendar.DATE); i++) { //日付けをオブジェクトに設定 cal.clear(); cal.set (year, month-1, i); // Since the month is specified from 0 to 11, I will give it -1. int weekday = cal.get(Calendar.DAY_OF_WEEK);

//日付を拡張 days[row][weekday-1] = i ; //System.out.println(days[row][weekday-1]);

	if(weekday % 7 ==0) {
		row ++;
	}
}

//出力 for (int k = 0; k < 6; k++) { for (int j = 0; j < 7; j++) {

			String res = String.valueOf(days[k][j]);

			if(days[k][j]==0) {
				System.out.print("   ");
			}else if(days[k][j] < 10) {
					System.out.print(" " + res + " ");

			}else if(days[k][j] >= 10) {
				res = res+" ";
				System.out.print(res);
			}
			if(j == 6) {
				System.out.println("\r\n");
			}
		}
	}
}

} ・ Main class

package foo;

import java.util.Scanner;

public class Makecal {

public static void main(String[] args) {

// TODO auto-generated method stub System.out.println ("Enter the year in 4 digits"); Scanner sc1 = new Scanner(System.in); System.out.println ("Enter month from 1 to 12"); Scanner sc2 = new Scanner(System.in);

	int year  = sc1.nextInt();
	int month = sc2.nextInt();

System.out.println ("year" + year + "year" + month + "month"); System.out.println("");

	Calmaker clm = new Calmaker();
	clm.Makecal(year,month);
}

}

image.png

the end.

Recommended Posts

I tried to display the calendar on the Eclipse console using Java.
I just want to write Java using Eclipse on my Mac
I tried to translate the error message when executing Eclipse (Java)
[Java] I tried to make a rock-paper-scissors game that beginners can run on the console.
I tried to decorate the simple calendar a little
I tried to operate SQS using AWS Java SDK
I tried using Log4j2 on a Java EE server
I tried using Java REPL
Input to the Java console
[JDBC] I tried to access the SQLite3 database from Java.
I tried to summarize the basics of kotlin and java
I tried to build the environment little by little using docker
I tried using Dapr in Java to facilitate microservice development
I tried using the CameraX library with Android Java Fragment
I tried to interact with Java
I tried to explain the method
I tried the Java framework "Quarkus"
I tried using JWT in Java
I tried to summarize Java learning (1)
I tried to summarize Java 8 now
I tried using Java memo LocalDate
I tried using GoogleHttpClient of Java
I want to use Java Applet easily on the command line without using an IDE
[Metal] I tried to figure out the flow until rendering using Metal
Special Lecture on Multi-Scale Simulation: I tried to summarize the 5th
I tried setting Java beginners to use shortcut keys in eclipse
I tried to summarize the methods of Java String and StringBuilder
I tried to move the Java compatible FaaS form "Fn Project"
Special Lecture on Multi-Scale Simulation: I tried to summarize the 7th
I tried using Elasticsearch API in Java
I tried to summarize the methods used
I want to display background-ground-image on heroku.
I tried the new era in Java
Connect from Java to MySQL using Eclipse
I tried to implement the Iterator pattern
I tried using OpenCV with Java + Tomcat
I tried to summarize the Stream API
I tried to build AdoptOpenjdk 11 on CentOS 7
[Java] How to use the Calendar class
Pre-processing to display on the browser (compiler)
[Java] Display the bit string stored in the byte type variable on the console
I want to display the number of orders for today using datetime.
[Introduction to Java] I tried to summarize the knowledge that I think is essential
I tried to make a talk application in Java using AI "A3RT"
I tried migrating the portfolio created on Vagrant to the Docker development environment
I tried to publish the reflex measurement application on the Google Play store
Display Japanese calendar and days of the week using java8 standard class
I tried using Docker for the first time
I was addicted to using RXTX on Sierra
I tried using Junit on Mac VScode Maven
[For beginners] I tried using DBUnit in Eclipse
I tried putting Java on my Mac easily
I tried to make Basic authentication with Java
[Rails] I tried to raise the Rails version from 5.0 to 5.2
[For beginners] I tried using JUnit 5 in Eclipse
I tried to organize the session in Rails
java I tried to break a simple block
I tried to implement deep learning in Java
[API] I tried using the zip code search API
I tried to output multiplication table in Java
Display "Hello World" in the browser using Java