Skip to main content
タグを編集
リンク
ita_3y
  • 2,797
  • 2
  • 11
  • 15
leap_year.javaがわかったので加えました。
ソース リンク
jui527
  • 73
  • 1
  • 8

leap_year.java
メソッド名は何でもおkclass leap_year{
int dim;
int uruudosi(int yy);
if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0){ うる
dim = 29; // うる年計算
2月末日返すelse
(2dim = 28または29)

cmd;
}
return dim;
}
cmd

Year?: 2015 
Month?: 2 
Su Mo Tu We Th Fr Sa 
 1  2  3  4  5  6  7 
 8  9 10 11 12 13 14 
15 16 17 18 19 20 21 
22 23 24 25 26 27 28

leap_year.java
メソッド名は何でもおk(){ うる年計算
2月末日返す
(28または29)

cmd

Year?: 2015 
Month?: 2 
Su Mo Tu We Th Fr Sa 
 1  2  3  4  5  6  7 
 8  9 10 11 12 13 14 
15 16 17 18 19 20 21 
22 23 24 25 26 27 28

leap_year.java
class leap_year{
int dim;
int uruudosi(int yy);
if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0){
dim = 29; // うる
else
dim = 28;
}
return dim;
}
cmd

Year?: 2015 
Month?: 2 
Su Mo Tu We Th Fr Sa 
 1  2  3  4  5  6  7 
 8  9 10 11 12 13 14 
15 16 17 18 19 20 21 
22 23 24 25 26 27 28
本文に 595 文字追加
ソース リンク
BLUEPIXY
  • 6,907
  • 1
  • 21
  • 34

import java.io.*;

public class sample53{
public static void main(String[] args) throws Exception{
BufferedReader in =
new BufferedReader(new InputStreamReader(System.in));

import java.io.*; 

public class sample53{ 
    public static void main(String[] args) throws Exception{ 
    BufferedReader in =  
        new BufferedReader(new InputStreamReader(System.in)); 

    System.out.print("Year?: "); 
    String str1 = in.readLine(); 
    System.out.print("Month?: "); 
    String str2 = in.readLine(); 

    int year = Integer.parseInt(str1); 
    int month = Integer.parseInt(str2); 
    int dow = dayofweek(year, month); 
    int dim = daysinmonth(year, month); 
     
    showcal(dow, dim); 
    } 
     
    // カレンダーを表示する 
    public static void showcal(int dow, int days) throws Exception{ 
    System.out.println("Su Mo Tu We Th Fr Sa"); 
     
    int d = 1; 
    int i; 

    // 最初の週の表示  
    for(i = 0; i < dow; i++){ 
        System.out.print("   "); 
    } 
    for(; i < 7; i++){ 
        System.out.print(" " + d + " "); 
        d++; 
    } 
    System.out.println(); 

    // 二週目以降の表示 
    for(int j = 0; d <= days; j++){ 
        for(i = 0; i < 7 && d <= days; i++){ 
        if(d < 10) 
            System.out.print(" " + d + " "); 
        else 
            System.out.print(d + " "); 
        d++; 
        } 
        System.out.println(); 
    } 
    } 
     
    // 月の日数をかえす 
    public static int daysinmonth(int year, int month) throws Exception{ 
    int dim = 31; 
    if(month == 4 || month == 6 || month == 9 || month == 11) 
        dim = 30; 
    if(month == 2){ 
        if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) 
        dim = 29; // うるう年 
        else 
        dim = 28; 
    } 
    return dim; 
    } 
     
    // 年の日数をかえす 
    public static int daysinyear(int year) throws Exception{ 
    int diy; 
    if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) 
        diy = 366; // うるう年 
    else 
        diy = 365; 
    return diy; 
    } 
     
    // 月の初日の曜日をかえす 
    public static int dayofweek(int year, int month) throws Exception{ 
    int days = 0; 
    int y = 0, m = 0; 
    int dow = 0; 

    // 2000年以降 
    if(year >= 2000){ 
        for(y = 2000; y < year; y++){ 
        days = days + daysinyear(y); 
        } 
        for(m = 1; m < month; m++){ 
        days = days + daysinmonth(year, m); 
        } 
        dow = (days + 6) % 7; 
    } 

    // 1999年以前 
    else{ 
        for(m = month; m <= 12; m++){ 
        days = days + daysinmonth(year, m); 
        } 
        for(y = year + 1; y < 2000; y++){ 
        days = days + daysinyear(y); 
        } 
        dow = 6 - days % 7; 
    } 
    return dow; 
    } 
} 

}

import java.util.Date;
import java.util.Calendar;

class day_of_week{

String yo(int b_yy, int b_mm , int b_dd){
Date today = new Date();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, b_yy);
cal.set(Calendar.MONTH, b_mm-1);
cal.set(Calendar.DATE,b_dd);

import java.util.Date; 
import java.util.Calendar; 


class day_of_week{ 

     
String yo(int b_yy, int b_mm , int b_dd){ 
    Date today = new Date(); 
    Calendar cal = Calendar.getInstance(); 
    cal.set(Calendar.YEAR, b_yy); 
    cal.set(Calendar.MONTH, b_mm-1); 
    cal.set(Calendar.DATE,b_dd); 
     
    int h = cal.get(Calendar.DAY_OF_WEEK); 
    String yo =""; 
    switch(h){ 
        case 1: yo = "日"; break; 
        case 2: yo = "月"; break; 
        case 3: yo = "火"; break; 
        case 4: yo = "水"; break; 
        case 5: yo = "木"; break; 
        case 6: yo = "金"; break; 
        case 7: yo = "土"; break; 
    } 
     
     
    return yo; 
    } 
} 

}

leap_year.java
class leap_year{
int dim;
int uruudosi(int yy)
if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0){
dim = 29; // うるう年
else
dim = 28;
}
return dim;
}

cmd

Year?: 2015
Month?: 2
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28

leap_year.java
メソッド名は何でもおk(年){ うるう年計算
2月末日返す
(28または29)

cmd

Year?: 2015 
Month?: 2 
Su Mo Tu We Th Fr Sa 
 1  2  3  4  5  6  7 
 8  9 10 11 12 13 14 
15 16 17 18 19 20 21 
22 23 24 25 26 27 28

import java.io.*;

public class sample53{
public static void main(String[] args) throws Exception{
BufferedReader in =
new BufferedReader(new InputStreamReader(System.in));

System.out.print("Year?: "); 
String str1 = in.readLine(); 
System.out.print("Month?: "); 
String str2 = in.readLine(); 

int year = Integer.parseInt(str1); 
int month = Integer.parseInt(str2); 
int dow = dayofweek(year, month); 
int dim = daysinmonth(year, month); 
 
showcal(dow, dim); 
} 
 
// カレンダーを表示する 
public static void showcal(int dow, int days) throws Exception{ 
System.out.println("Su Mo Tu We Th Fr Sa"); 
 
int d = 1; 
int i; 

// 最初の週の表示  
for(i = 0; i < dow; i++){ 
    System.out.print("   "); 
} 
for(; i < 7; i++){ 
    System.out.print(" " + d + " "); 
    d++; 
} 
System.out.println(); 

// 二週目以降の表示 
for(int j = 0; d <= days; j++){ 
    for(i = 0; i < 7 && d <= days; i++){ 
    if(d < 10) 
        System.out.print(" " + d + " "); 
    else 
        System.out.print(d + " "); 
    d++; 
    } 
    System.out.println(); 
} 
} 
 
// 月の日数をかえす 
public static int daysinmonth(int year, int month) throws Exception{ 
int dim = 31; 
if(month == 4 || month == 6 || month == 9 || month == 11) 
    dim = 30; 
if(month == 2){ 
    if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) 
    dim = 29; // うるう年 
    else 
    dim = 28; 
} 
return dim; 
} 
 
// 年の日数をかえす 
public static int daysinyear(int year) throws Exception{ 
int diy; 
if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) 
    diy = 366; // うるう年 
else 
    diy = 365; 
return diy; 
} 
 
// 月の初日の曜日をかえす 
public static int dayofweek(int year, int month) throws Exception{ 
int days = 0; 
int y = 0, m = 0; 
int dow = 0; 

// 2000年以降 
if(year >= 2000){ 
    for(y = 2000; y < year; y++){ 
    days = days + daysinyear(y); 
    } 
    for(m = 1; m < month; m++){ 
    days = days + daysinmonth(year, m); 
    } 
    dow = (days + 6) % 7; 
} 

// 1999年以前 
else{ 
    for(m = month; m <= 12; m++){ 
    days = days + daysinmonth(year, m); 
    } 
    for(y = year + 1; y < 2000; y++){ 
    days = days + daysinyear(y); 
    } 
    dow = 6 - days % 7; 
} 
return dow; 
} 

}

import java.util.Date;
import java.util.Calendar;

class day_of_week{

String yo(int b_yy, int b_mm , int b_dd){
Date today = new Date();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, b_yy);
cal.set(Calendar.MONTH, b_mm-1);
cal.set(Calendar.DATE,b_dd);

int h = cal.get(Calendar.DAY_OF_WEEK); 
String yo =""; 
switch(h){ 
    case 1: yo = "日"; break; 
    case 2: yo = "月"; break; 
    case 3: yo = "火"; break; 
    case 4: yo = "水"; break; 
    case 5: yo = "木"; break; 
    case 6: yo = "金"; break; 
    case 7: yo = "土"; break; 
} 
 
 
return yo; 
} 

}

leap_year.java
class leap_year{
int dim;
int uruudosi(int yy)
if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0){
dim = 29; // うるう年
else
dim = 28;
}
return dim;
}

cmd

Year?: 2015
Month?: 2
Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28

import java.io.*; 

public class sample53{ 
    public static void main(String[] args) throws Exception{ 
    BufferedReader in =  
        new BufferedReader(new InputStreamReader(System.in)); 

    System.out.print("Year?: "); 
    String str1 = in.readLine(); 
    System.out.print("Month?: "); 
    String str2 = in.readLine(); 

    int year = Integer.parseInt(str1); 
    int month = Integer.parseInt(str2); 
    int dow = dayofweek(year, month); 
    int dim = daysinmonth(year, month); 
     
    showcal(dow, dim); 
    } 
     
    // カレンダーを表示する 
    public static void showcal(int dow, int days) throws Exception{ 
    System.out.println("Su Mo Tu We Th Fr Sa"); 
     
    int d = 1; 
    int i; 

    // 最初の週の表示  
    for(i = 0; i < dow; i++){ 
        System.out.print("   "); 
    } 
    for(; i < 7; i++){ 
        System.out.print(" " + d + " "); 
        d++; 
    } 
    System.out.println(); 

    // 二週目以降の表示 
    for(int j = 0; d <= days; j++){ 
        for(i = 0; i < 7 && d <= days; i++){ 
        if(d < 10) 
            System.out.print(" " + d + " "); 
        else 
            System.out.print(d + " "); 
        d++; 
        } 
        System.out.println(); 
    } 
    } 
     
    // 月の日数をかえす 
    public static int daysinmonth(int year, int month) throws Exception{ 
    int dim = 31; 
    if(month == 4 || month == 6 || month == 9 || month == 11) 
        dim = 30; 
    if(month == 2){ 
        if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) 
        dim = 29; // うるう年 
        else 
        dim = 28; 
    } 
    return dim; 
    } 
     
    // 年の日数をかえす 
    public static int daysinyear(int year) throws Exception{ 
    int diy; 
    if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) 
        diy = 366; // うるう年 
    else 
        diy = 365; 
    return diy; 
    } 
     
    // 月の初日の曜日をかえす 
    public static int dayofweek(int year, int month) throws Exception{ 
    int days = 0; 
    int y = 0, m = 0; 
    int dow = 0; 

    // 2000年以降 
    if(year >= 2000){ 
        for(y = 2000; y < year; y++){ 
        days = days + daysinyear(y); 
        } 
        for(m = 1; m < month; m++){ 
        days = days + daysinmonth(year, m); 
        } 
        dow = (days + 6) % 7; 
    } 

    // 1999年以前 
    else{ 
        for(m = month; m <= 12; m++){ 
        days = days + daysinmonth(year, m); 
        } 
        for(y = year + 1; y < 2000; y++){ 
        days = days + daysinyear(y); 
        } 
        dow = 6 - days % 7; 
    } 
    return dow; 
    } 
} 
import java.util.Date; 
import java.util.Calendar; 


class day_of_week{ 

     
String yo(int b_yy, int b_mm , int b_dd){ 
    Date today = new Date(); 
    Calendar cal = Calendar.getInstance(); 
    cal.set(Calendar.YEAR, b_yy); 
    cal.set(Calendar.MONTH, b_mm-1); 
    cal.set(Calendar.DATE,b_dd); 
     
    int h = cal.get(Calendar.DAY_OF_WEEK); 
    String yo =""; 
    switch(h){ 
        case 1: yo = "日"; break; 
        case 2: yo = "月"; break; 
        case 3: yo = "火"; break; 
        case 4: yo = "水"; break; 
        case 5: yo = "木"; break; 
        case 6: yo = "金"; break; 
        case 7: yo = "土"; break; 
    } 
     
     
    return yo; 
    } 
} 

leap_year.java
メソッド名は何でもおk(年){ うるう年計算
2月末日返す
(28または29)

cmd

Year?: 2015 
Month?: 2 
Su Mo Tu We Th Fr Sa 
 1  2  3  4  5  6  7 
 8  9 10 11 12 13 14 
15 16 17 18 19 20 21 
22 23 24 25 26 27 28
本文に 122 文字追加
ソース リンク
jui527
  • 73
  • 1
  • 8
読み込んでいます
ソース リンク
jui527
  • 73
  • 1
  • 8
読み込んでいます