class data {    private int yue;
    private int day;
    public static int num = 0;    public int Get_yue(int m) {
        yue = m;
        return yue;
    }    public int Get_day(int n) {
        day = n;
        return day;
    }    public void Set() {
        while (yue > 0 && yue <= 12) {
            for (int i = 1; i <= yue; i++) {
                switch (i) {
                    case 1:
                    case 3:
                    case 5:
                    case 7:
                    case 8:
                    case 10:
                    case 12:
                        num = num + 31;
                        break;
                    case 2:
                        num = num + 29;
                        break;
                    case 4:
                    case 6:
                    case 9:
                    case 11:
                        num = num + 30;
                        break;
                }
            }
        }
    }    public void print() {
        int DATA;
        DATA = num + day;
        System.out.println("2007年" + yue + "月"
                + day + "日是这一当中的" + DATA + "天");
    }
}    public class D_data {        public static void main(String[] args) {
            int x=3,y=4;
           //System.out.println("请输入日期:x y");
           // x=(int)System.in.read();
           // x=(int)System.in.read();
            data D = new data();
            D.Get_yue(x);
            D.Get_day(y);
            D.Set();
            D.print();
            }
    }程序没有报错,但是没有结果!各位帮我 看下啊 !还有如果我 想用键盘输入,应添加什么 代码?

解决方案 »

  1.   

    while (yue > 0 && yue <= 12) 
    这个死循环了,yue永远不改变,永远跳不出循环,当然也没法运行到D.print()这句了
      

  2.   

    import java.util.*;
    import java.io.*;public class IO
    {
    public static void main(String[] args)
    {
    int input;
    String str;
    Scanner s = new Scanner(System.in);
    input = s.nextInt();//读取一个数字
    str = s.next();//读取字符串
    System.out.println(input);//输出数字
    System.out.println(str);//输出字符串
    }
    }
    用键盘输入
      

  3.   

    Scanner sc=new Scanner(System.in);
    sc.next();
    其实有Calendar的,介个很强大
      

  4.   

    while (yue > 0 && yue <= 12)改成if (yue > 0 && yue <= 12)就好了。
      

  5.   

    import java.util.Scanner;
    //獲得鍵盤輸入需要導入 包
    class Hello {
    public int jisuan(int month)
    {
    int all=0;
    for (int i = 1; i <= month; i++) {
    if (month==1||month==3||month==5||month==7||month==8||month==10||month==12) {
    all=all+31;
    }
    else if (month==2) {
    all=all+28;
    }else {
    all=all+30;
    }
    }
    return all;
    }}public class Help { public static void main(String[] args) {
    //問題不是很複雜,不要把它想的那麼麻煩
    System.out.println("請輸入月份: ");
    //下面一句話是獲得鍵盤輸入的方法
    Scanner input=new Scanner(System.in);
    int month=input.nextInt();
    System.out.println("請輸入日期");
    int day=input.nextInt();
            int all=0;
            Hello he=new Hello();
            all=all+he.jisuan(month)+day;
    System.out.println("2007年"+month+"月"+day+"日"+"是這一年的第"+all+"天");
    //不知道能不能看懂我的解決方案如果不懂的話留言........

    }
    }