ユーザーが入力した日付がうるう年かどうかを計算するプログラムがあります。私はそれがすべてダウンだと思うが、私はまた、入力された日付がバイナリの日付(すなわち1/1/11)であるかどうかを確認する必要があります。私は本当にこれについて行くための最善の方法は、多分charAtの参照?すべてのヘルプは必見いただければ幸いです!java - 日付がバイナリかどうかを調べる
//****************************
import java.util.Scanner;
public class leapYearCalc {
private int day = 0;
private int month = 0;
private int year = 0;
Scanner myScan = new Scanner (System.in);
//---------------------------------
//Constructor to accept and initialize instance data
//---------------------------------
public leapYearCalc(int day, int month, int year){
this.day=day;
this.month=month;
this.year=year;
}
//--------------------------------
//Get day
//--------------------------------
public int getDay(){
System.out.println("Whats the day?");
day = myScan.nextInt();
return day;
}
//--------------------------------
//Get day
//--------------------------------
public int getMonth(){
System.out.println("Whats the month in numerical form?");
month = myScan.nextInt();
return month;
}
//--------------------------------
//Get day
//--------------------------------
public int getYear(){
System.out.println("Whats the year (i.e. 2004)?");
year = myScan.nextInt();
if (year<1582)
System.out.println("Please enter a value above 1582");
return year;
}
//--------------------------------
//1. If a year is divisible by 4 it is a leap year if 2 does not apply.
//2. If a year is divisible by 100 it is not a leap year unless #3 applies.
//3. If a year is divisible by 400 it is a leap year.
//--------------------------------
//Calculate leap year
public String toString() {
if (year % 4 == 0) {
if (year % 100 != 0) {
System.out.println(year + " is a leap year.");
}
else if (year % 400 == 0) {
System.out.println(year + " is a leap year.");
}
else {
System.out.println(year + " is not a leap year.");
}
}
else {
System.out.println(year + " is not a leap year.");
}
return null;
}
//--------------------------------
//Check to see if date is binary
//--------------------------------
public int getBinary(){
while(month == 01 || month == 10)
if(day == 01 || day == 10 && year == 00 || year == 01)
System.out.println("It's a binary date!");
System.out.println("It's not a binary date");
return month;
}
}
すべての数字が0または1であるかどうかを確認するのはどれくらい難しいですか? –
これは宿題の場合宿題タグを追加する必要があります –
oohh、私は宿題タグがあるかどうかわかりませんでした。ありがとう! – bjstone15