"year cannot be resolved to a variable"
import java.util.Scanner;
/ / if 1900.1.1 is Sunday ~ ~ ~ ~ what day is??
public class calendar {
public static void main (String [] args) {
Scanner in = new Scanner (System.in);
System.out.println ("input year month day:") ;/ / sample 20130509
System.out.println ("sample 20130507");
String calendar = in.next ();
int date = Integer.parseInt (calendar);
int inyear = date/10000;
int inday = date% 1000000;
int inmonth = date% 10000/100;
int sum = 0;
for (int year = 1900; year <= inyear-1; year + +) {
if (year% 4 == 0 && year% 100 = 0 |! |! year% 400 = 0) {
sum + = 366;}
else {
sum + = 365;}
}
for (int month = 1; month
/ / System.out.println (year);
if (! year% 4 == 0 && year% 100 = 0 | | year% 400 = 0!) {/ / error here year ! ! !
sum + = 29;}
else {
sum + = 28;}
}
else {
if (month == 4 | | month == 6 | | month == 9 | | month == 11) {
sum + = 30;}
else {
sum + = 30;}
}
}
sum + = inday;
System.out.println (sum + "days");
}
}
------ Solution ----------------------------------- ---------
year is temporary variables on cycles , the cycle is over , of course released ah.
if not wrong, then , given that month cycle should inyear fishes ah.
------ For reference only -------------------------------------- -
brain pumping , should inyear ...
variable value year after if I really need to cycle , how should I do it?
------ For reference only -------------------------------------- -
brain pumping , should inyear ...
variable value year after if I really need to cycle , how should I do it?
int year = 1900;
for (; year <= inyear-1; year + +)
没有评论:
发表评论