我刚学java,编了一个简单的程序为什么老是错误啊,求大神指教

importjavax.swing.JOptionPane;publicclassJudgeDate{publicstaticvoidmain(Stringargs){S... import javax.swing.JOptionPane;

public class JudgeDate {
public static void main(String args) {
String dataYearString = JOptionPane.showInputDialog("Please enter the year: ");
int dataYear = Integer.parseInt(dataYearString);
String dataMonthString = JOptionPane.showInputDialog("Please enter the month: ");
int dataMonth = Integer.parseInt(dataMonthString);
String dataDayString = JOptionPane.showInputDialog("Please enter the day of the month: ");
int dataDay = Integer.parseInt(dataDayString);
int dataDate = dateJudging(dataYear,dataMonth,dataDay);
JOptionPane.showMessageDialog(null,"Day of the week is "+ dateConvert(dataDate));
}

public static int dateJudging( int dataYear,int dataMonth,int dataDay ) {
int q=0;
int m=0;
int j=0;
int k=0;
int h=0;
int y = dataYear;
/* set q */
if ( dataMonth == 2 ) {
if (( dataYear % 100 ) == 0 ){
if (( dataYear % 400 ) == 0 ) q = 29;
else q = 28;
}
else if (( dataYear % 4 ) == 0) q = 29;
else q = 28;
}
else if ((dataMonth == 1)||(dataMonth == 3)||(dataMonth == 5)||(dataMonth == 7)||(dataMonth == 8)||(dataMonth == 10)||(dataMonth == 12)) q = 31;
else if ((dataMonth == 4)||(dataMonth == 6)||(dataMonth == 9)||(dataMonth == 11)) q = 30;
/* set m and year */
if ((dataMonth == 1)||(dataMonth == 2)) {
m = dataMonth + 12;
y -= 1;
}
/** set j */
j = (int)(y / 100);
/** set k */
k = y % 100;
/** compute h */
h = (q + (int)(26 * (m + 1) / 10) + k + (int)(k / 4) + (int)(j / 4) + (5 * j)) % 7;
return h;
}
public static String dateConvert(int dataDate) {
String dateString;
switch (dataDate) {
case 0 : dateString = "Saturday";
break;
case 1 : dateString = "Sunday";
break;
case 2 : dateString = "Monday";
break;
case 3 : dateString = "Tuesday";
break;
case 4 : dateString = "Wedensday";
break;
case 5 : dateString = "Thursday";
break;
case 6 : dateString = "Friday";
break;
}
return dateString;
}
}
展开
 我来答
百度网友845f74e61
2013-04-16 · TA获得超过6929个赞
知道大有可为答主
回答量:4050
采纳率:50%
帮助的人:1615万
展开全部

  给你改了一下,主要是错了两个地方

main(String[] args)   参数是个数组。

String dateString = "";  需要一个默认值。

import javax.swing.JOptionPane;
public class JudgeDate {
public static void main(String[] args) {
String dataYearString = JOptionPane
.showInputDialog("Please enter the year: ");
int dataYear = Integer.parseInt(dataYearString);
String dataMonthString = JOptionPane
.showInputDialog("Please enter the month: ");
int dataMonth = Integer.parseInt(dataMonthString);
String dataDayString = JOptionPane
.showInputDialog("Please enter the day of the month: ");
int dataDay = Integer.parseInt(dataDayString);
int dataDate = dateJudging(dataYear, dataMonth, dataDay);
JOptionPane.showMessageDialog(null, "Day of the week is "
+ dateConvert(dataDate));
}
public static int dateJudging(int dataYear, int dataMonth, int dataDay) {
int q = 0;
int m = 0;
int j = 0;
int k = 0;
int h = 0;
int y = dataYear;
/* set q */
if (dataMonth == 2) {
if ((dataYear % 100) == 0) {
if ((dataYear % 400) == 0)
q = 29;
else
q = 28;
} else if ((dataYear % 4) == 0)
q = 29;
else
q = 28;
} else if ((dataMonth == 1) || (dataMonth == 3) || (dataMonth == 5)
|| (dataMonth == 7) || (dataMonth == 8) || (dataMonth == 10)
|| (dataMonth == 12))
q = 31;
else if ((dataMonth == 4) || (dataMonth == 6) || (dataMonth == 9)
|| (dataMonth == 11))
q = 30;
/* set m and year */
if ((dataMonth == 1) || (dataMonth == 2)) {
m = dataMonth + 12;
y -= 1;
}
/** set j */
j = (int) (y / 100);
/** set k */
k = y % 100;
/** compute h */
h = (q + (int) (26 * (m + 1) / 10) + k + (int) (k / 4) + (int) (j / 4) + (5 * j)) % 7;
return h;
}
public static String dateConvert(int dataDate) {
String dateString = "";
switch (dataDate) {
case 0:
dateString = "Saturday";
break;
case 1:
dateString = "Sunday";
break;
case 2:
dateString = "Monday";
break;
case 3:
dateString = "Tuesday";
break;
case 4:
dateString = "Wedensday";
break;
case 5:
dateString = "Thursday";
break;
case 6:
dateString = "Friday";
break;
}
return dateString;
}
}

飞致陌地
2013-04-15
知道答主
回答量:20
采纳率:0%
帮助的人:17.8万
展开全部

这位网友你好,你的错误有两个


1、public static void main(String[] args)

    main方法的参数里面应该是String[] 数组的格式。请仔细看你的格式写法

2、dateConvert  方法里面的String dateString 声明请改为

    String dateString = "";

我把我改完的文件上传了一份附件给你,请看一下

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
草蛋头看世记
2013-04-15
知道答主
回答量:89
采纳率:0%
帮助的人:16.1万
展开全部
1、开头的 public static void main(String args) { 改为 public static void main(String[] args) {
2、未初始化变量dateString,在 定义dateString时定义为String dateString = null;
然后编译执行就成功了。
这是你初学时编写的吗?这么强!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式