错误:重复本地变量yearb 我被要求把月,年,日3个单独的变量。
您将这些值发送到convertdays方法,该方法将使用以下公式以一个长整数的形式返回日期:您的长年将是年份的总和乘以10000,月份乘以100,以及那天。这是一个用于将日期放在可以排序的表单中的公式(我们不会对日期进行排序,只是将其放入可以排序的表单中)。回到主页,你将打印这个标记的长整数。
/* rayane seridj
* 5-10
* */
import java.util.Scanner;
public class hw2222
{
public static void main (String [] args)
{
int month, day, year,dates,yearb;
Scanner input = new Scanner(System.in);
System.out.print("Please Enter Date in The Format mm/dd/yyyy : ");
month = input.nextInt();
day = input.nextInt();
year = input.nextInt();
boolean yearb;
yearb = leap(year);
if (yearb == true)
System.out.println (year + " is a leap year ");
else
System.out.println (year + " is not a leap year");
}
public static int convertdays (int month ,int day, int year)
{
int yy,dd,mm,dates;
yy =10000 *year;
mm = 100 *month;
dd= day;
dates =yy + mm +dd;
return dates;
}
public static boolean leap(int year)
{
if (year % 400 == 0 || (year % 4 ==0 && year %100 !=0))
return true;
else
return false;
}
}
答案 0 :(得分:0)
您声明变量yearb
两次:
int month, day, year,dates,yearb;
boolean yearb;
变量只能在特定的上下文中声明一次(方法,全局等)。
尝试下面的代码(注意一个名为isLeap
的新变量):
/* rayane seridj
* 5-10
* */
import java.util.Scanner;
public class hw2222
{
public static void main (String [] args)
{
int month, day, year,dates,yearb;
Scanner input = new Scanner(System.in);
System.out.print("Please Enter Date in The Format mm/dd/yyyy : ");
month = input.nextInt();
day = input.nextInt();
year = input.nextInt();
boolean isLeap;
isLeap = leap(year);
if (isLeap)
System.out.println (year + " is a leap year ");
else
System.out.println (year + " is not a leap year");
}
public static int convertdays (int month ,int day, int year)
{
int yy,dd,mm,dates;
yy =10000 *year;
mm = 100 *month;
dd= day;
dates =yy + mm +dd;
return dates;
}
public static boolean leap(int year)
{
if (year % 400 == 0 || (year % 4 ==0 && year %100 !=0))
return true;
else
return false;
}
}