当前位置: 代码迷 >> Java相关 >> 为什么编译没问题运行有问题??
  详细解决方案

为什么编译没问题运行有问题??

热度:318   发布时间:2007-04-19 17:25:22.0
为什么编译没问题运行有问题??

import java.util.*;
class A{
private int b;
private int d;
A(){
b=1;
}
//输入年月时计算日历
void B(int year,int month){
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
d=31;
if(month==4||month==6||month==9||month==11)
d=30;
if(month==2){
if(year%400==0||year%100!=0&&year%4==0)
d=29;
else
d=28;
System.out.println(year+"年"+month+"月");
System.out.println("一 二 三 四 五 六 日");
for(int i=1;i<=d;i++)
{
System.out.print(i );
if(b+7<i)
{
b+=7;
System.out.println();
}
}
}
}//不输入数据计算该月的日历
void C(){
int month,year;
Calendar today;
today=Calendar.getInstance();
month=today.get(Calendar.MONTH);
year=today.get(Calendar.YEAR);
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
d=31;
if(month==4||month==6||month==9||month==11)
d=30;
if(month==2){
if(year%400==0||year%100!=0&&year%4==0)
d=29;
else
d=28;
System.out.println(year+"年"+month+"月");
System.out.println("一 二 三 四 五 六 日");
for(int j=1;j<=d;j++)
{
System.out.print(j );
if(b+7<j)
{
b+=7;
System.out.println();
}
}
}

}
}
public class Date1{
Date1(){}
public static void main(String[]args)
{
Scanner bb=new Scanner(System.in);
A rr=new A();
int a,b;
a=bb.nextInt();
b=bb.nextInt();
if(a>0)
{
rr.B(a,b);
}else{
rr.C();
}
}
}
搜索更多相关的解决方案: 编译  运行  

----------------解决方案--------------------------------------------------------
帮帮我这新手好吗??
----------------解决方案--------------------------------------------------------

为什么在JBuilder能运行。。在DOS里不可以的??


----------------解决方案--------------------------------------------------------
以下是引用w289592467在2007-4-19 17:25:22的发言:

程序代码:

import java.util.*;
class A{
private int b;
private int d;
A(){
b=1;
}
//输入年月时计算日历
void B(int year,int month){
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
d=31;
if(month==4||month==6||month==9||month==11)
d=30;
if(month==2){
if(year%400==0||year%100!=0&&year%4==0)
d=29;
else
d=28;
} //这里加个括号!!
System.out.println(year+\"年\"+month+\"月\");
System.out.println(\"一 二 三 四 五 六 日\");
for(int i=1;i<=d;i++)
{
System.out.print(i );
if(b+7<i)
{
b+=7;
System.out.println();
}
}
//} 把这个括号去掉!!
}//不输入数据计算该月的日历
void C(){
int month,year;
Calendar today;
today=Calendar.getInstance();
month=today.get(Calendar.MONTH);
year=today.get(Calendar.YEAR);
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
d=31;
if(month==4||month==6||month==9||month==11)
d=30;
if(month==2){
if(year%400==0||year%100!=0&&year%4==0)
d=29;
else
d=28;
}// 同理
System.out.println(year+\"年\"+month+\"月\");
System.out.println(\"一 二 三 四 五 六 日\");
for(int j=1;j<=d;j++)
{
System.out.print(j );
if(b+7<j)
{
b+=7;
System.out.println();
}
}
}

// }同理
}
public class Date1{
Date1(){}
public static void main(String[]args)
{
Scanner bb=new Scanner(System.in);
A rr=new A();
int a,b;
a=bb.nextInt();
b=bb.nextInt();
if(a>0)
{
rr.B(a,b);
}else{
rr.C();
}
}
}


----------------解决方案--------------------------------------------------------

  相关解决方案