标题:JAVA新手求助,看看哪里错了
只看楼主
男孩的诗
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-4-1
结帖率:50%
已结贴  问题点数:20 回复次数:6 
JAVA新手求助,看看哪里错了
输出星期的代码,求大神指点!!
public class Weekend {
     public static void main(String args[])
  {
        String stringNumber;String week="";
        int number = 0;
        while(number<1||number>7)  {
             stringNumber = JOptionPane.showInputDialog( "输入一个数(1---7)");
             number = Integer.parseInt( stringNumber );
      }
        switch(number)
  {           case 1 :   week ="星期一";break;
              case 2 :   week ="星期二";break;
              case 3 :   week ="星期三";break;
              case 4 :   week ="星期四";break;
              case 5 :   week ="星期五";break;
              case 6 :   week ="星期六";break;
              case 7 :   week ="星期日";break;      
      }
      JOptionPane.showMessageDialog( null,"星期是:"+week,"结果",JOptionPane.PLAIN_MESSAGE);
      System.exit(0);
  }
}      


报错:

--------------------Configuration: Java <Default>--------------------
D:\JCreator Pro\MyProjects\FindMax\weekend\Weekend.java:7: 找不到符号
符号: 变量 JOptionPane
位置: 类 Weekend
             stringNumber = JOptionPane.showInputDialog( "输入一个数(1---7)");
                            ^
D:\JCreator Pro\MyProjects\FindMax\weekend\Weekend.java:19: 找不到符号
符号: 变量 JOptionPane
位置: 类 Weekend
      JOptionPane.showMessageDialog( null,"星期是:"+week,"结果",JOptionPane.PLAIN_MESSAGE);
                                                           ^
D:\JCreator Pro\MyProjects\FindMax\weekend\Weekend.java:19: 找不到符号
符号: 变量 JOptionPane
位置: 类 Weekend
      JOptionPane.showMessageDialog( null,"星期是:"+week,"结果",JOptionPane.PLAIN_MESSAGE);
      ^
3 错误

Process completed.
搜索更多相关主题的帖子: public number JAVA 
2014-04-01 18:52
a674632745
Rank: 1
等 级:新手上路
帖 子:2
专家分:4
注 册:2014-4-1
得分:4 
import javax.swing.JOptionPane;

public class Father{
     public static void main(String args[])
  {
        String stringNumber;
        String week="";
        int number = 0;
        while(number<1||number>7)  
        {
             stringNumber = JOptionPane.showInputDialog( "输入一个数(1---7)");
             number = Integer.parseInt( stringNumber );
         }
        switch(number){           
              case 1 :   week ="星期一";break;
              case 2 :   week ="星期二";break;
              case 3 :   week ="星期三";break;
              case 4 :   week ="星期四";break;
              case 5 :   week ="星期五";break;
              case 6 :   week ="星期六";break;
              case 7 :   week ="星期日";break;      
      }
      JOptionPane.showMessageDialog( null,"星期是:"+week,"结果",JOptionPane.PLAIN_MESSAGE);
      System.exit(0);
  }
}
2014-04-01 22:06
zjcl817
Rank: 4
来 自:残狼部落
等 级:业余侠客
威 望:2
帖 子:68
专家分:206
注 册:2013-11-11
得分:4 
导入JOptionPane类就能够显示了!
2014-04-02 09:05
男孩的诗
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2014-4-1
得分:0 
回复 3楼 zjcl817
谢谢 ,知道了。能再请教一个程序么?
又写了一个程序:100——1000的水仙花数
 public class Shuixianhuashu
   {
       public static void main(String args[]);
       {
         int b1 , b2 , b3;
           for( int m = 101;m<1000;m++)
            {
                b3 = m/100;
                b2 = m%100/10;
                b1 = m%10;
                if( (b3*b3*b3*+b2*b2*b2+b1*b1*b1) ==m)
                  {
                      System.out.println(m+"是一个水仙花数");
                 }
            }
        }
}            


报错:

--------------------Configuration: Java <Default>--------------------
D:JCreator ProMyProjectsFindMaxweekendWeekend.java:1: 类 Shuixianhuashu 是公共的,应在名为 Shuixianhuashu.java 的文件中声明
 public class Shuixianhuashu
        ^
D:JCreator ProMyProjectsFindMaxweekendWeekend.java:3: 缺少方法主体,或声明抽象
       public static void main(String args[]);
                          ^
2 错误

Process completed.
2014-04-02 12:18
瞬间永恒
Rank: 1
等 级:新手上路
帖 子:2
专家分:4
注 册:2014-4-2
得分:4 
回复 4楼 男孩的诗
public static void main(String args[]);去掉后面分号
2014-04-02 15:05
jiewen
Rank: 2
等 级:论坛游民
威 望:1
帖 子:5
专家分:17
注 册:2014-4-1
得分:4 
回复 4楼 男孩的诗
即使去掉主函数后面的分号,程序虽然没有错误但是运行结果不对,原因是算法错误,程序修改如下:
public class ShuiXianHuaSu
{
    public static void main(String args[])

    {
        int b1, b2, b3, n;
        for(int m = 100; m < 1000; m++)
        {
            n = m;
            b1 = n % 10;
            n = n / 10;
            b2 = n % 10;
            b3 = n / 10;
            //System.out.println(b3);
            n = b1 * b1 * b1 + b2 * b2 * b2 + b3 * b3 * b3;
            //System.out.println(n);
            if (n == m)
            {
                System.out.println(m + "是一个水仙花数");
            }
        }
    }
}
2014-04-03 22:24
菜鸟yang
Rank: 1
等 级:新手上路
帖 子:1
专家分:4
注 册:2014-4-4
得分:4 
public class ShuiXianHuaShu {

    public static void main(String[] args) {

        for (int i = 100; i < 1000; i++) {

            double b1 = i / 100; //获取百分位
            double b2 = i % 100 / 10; //获取十分位
            double b3 = i % 10; //获取个位

            if (Math.pow(b1, 3) + Math.pow(b2, 3) + Math.pow(b3, 3) == i) {

                System.out.println("水仙花数是:" + i);
            }
        }
    }

}
2014-04-04 18:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-429529-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.293581 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved