十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
改了下,终于改好了。。。
景洪网站制作公司哪家好,找创新互联公司!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设公司等网站项目制作,到程序开发,运营维护。创新互联公司从2013年创立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联公司。
楼上改的还是有点问题,因为他原程序并不能正确显示日期。。。
1.数组ARR没有初始化。
2.F1和F2没有初始化。
3.打印日期的逻辑有问题。
4.计算var的逻辑有问题。
package test;
import java.applet.Applet;
import java.awt.Button;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.Date;
public class Cal extends Applet implements ActionListener {
Label L1 = new Label("输入年份");
Label L2 = new Label("输入月份");
TextField F1 = new TextField(5);
TextField F2 = new TextField(5);
Button B1 = new Button("查询");
int arr[] = new int[12];
String ARR[];
int var;
public void init() {
add(L1);
add(F1);
add(L2);
add(F2);
add(B1);
Date date = new Date();
F1.setText(String.valueOf(date.getYear() + 1900));
F2.setText(String.valueOf(date.getMonth() + 1));
B1.addActionListener(this);
arr[0] = arr[2] = arr[4] = arr[6] = arr[7] = arr[9] = arr[11] = 31;
arr[3] = arr[5] = arr[8] = arr[10] = 30;
date.setDate(1);
var = date.getDay();
}
public void actionPerformed(ActionEvent e) {
int x = Integer.parseInt(F1.getText()), i = Integer.parseInt(F2
.getText()) - 1, s = 0;
Date date = new Date();
date.setYear(x - 1900);
date.setMonth(i);
date.setDate(1);
var = date.getDay();
repaint();
}
public void paint(Graphics g) {
int xpos, ypos;
arr[0] = arr[2] = arr[4] = arr[6] = arr[7] = arr[9] = arr[11] = 31;
arr[3] = arr[5] = arr[8] = arr[10] = 30;
int x = Integer.parseInt(F1.getText()), i = Integer.parseInt(F2
.getText()) - 1;
if ((x % 4 == 0 x % 100 != 0) || (x % 400 == 0))
arr[1] = 29;
else
arr[1] = 28;
g.drawString("星期一", 50, 50);
g.drawString("星期二", 100, 50);
g.drawString("星期三", 150, 50);
g.drawString("星期四", 200, 50);
g.drawString("星期五", 250, 50);
g.drawString("星期六", 300, 50);
g.drawString("星期日", 350, 50);
ARR = new String[arr[i]];
int j = 0, k = 1;
while (k = arr[i]) {
ARR[j] = String.valueOf(k);
k ++;
j ++;
}
int line = 0;
for (int m = 0 ; m ARR.length ; m ++) {
ypos = 50 + 50 * (line + 1);
xpos = (var * 50 + 50 * (m % 7)) % 350;
if (xpos == 0) {
xpos = 350;
line ++;
}
g.drawString(ARR[m], xpos, ypos);
}
}
}
代码喝注释如下:
public static void main(String[] args) { System.out.print("Please input the month to check:"); int month = new Scanner(System.in).nextInt();//月份//月份不在1~12的情况,提醒输入错误 if (month = 0 || month 12) { System.out.println("Error! month must be between 1 and 12!"); }
//1-3月是春天
else if (month = 3) { System.out.println("Month " + month + " is in Spring!"); }
//4-6月是夏天
else if (month = 6) { System.out.println("Month " + month + " is in Summer!"); }
//7-9月是秋天
else if (month = 9) { System.out.println("Month " + month + " is in Autumn!"); }
//10-12月是冬天
else { System.out.println("Month " + month + " is in Winter!"); } }
import java.util.Scanner;
public class $ {
private static int[] DAYS = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("输入年份:");
int year = in.nextInt();
System.out.print("输入月份:");
int month = in.nextInt();
String str = year + "-" + month + ":";
// 闰年二月份
if (year % 400 == 0 || (year % 4 == 0 year % 100 != 0) month == 2) {
str += 29;
} else {
str += DAYS[month - 1];
}
System.out.println(str);
}
}
java获取一个时间的年月日代码及相关解释说明参考下面代码
package zhidao;
import java.util.Calendar;
public class Test {
public static void main(String[] args) {
Calendar cal=Calendar.getInstance();//使用日历类
int year=cal.get(Calendar.YEAR);//获取年份
int month=cal.get(Calendar.MONTH)+1;//获取月份,因为从0开始的,所以要加1
int day=cal.get(Calendar.DAY_OF_MONTH);//获取天
System.out.println("结果:"+year+"-"+month+"-"+day);
}
}