标题:需要标识符?非法的类型开始?我快疯了
只看楼主
杨松松
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:98
专家分:142
注 册:2011-12-3
结帖率:91.67%
已结贴  问题点数:20 回复次数:10 
需要标识符?非法的类型开始?我快疯了
    import java.util.Scanner;
    public class ScoreTest{
        public static void main(String[] args){
            Scanner reader=new Scanner(System.in);
            double score[];
            int n;
            System.out.println("您要输入多少个学生的成绩");
            n=reader.nextInt();
            if(n<=0)
              System.out.printfln("个数错误!");
                 else
              score=new double[n];
                             for(int i=0;i<n;i++){
                                   System.out.print("请输入第"+(i+1)"个童鞋的成绩:");
                                      score[i]=reader.nextDouble();
                }
              Info.showInfo(n,score);
                           
            
    }
    class Info{
        public void showInfo(int n,double score[]){
                    Scanner reader=new Scanner(System.in);
            System.out.println("您想查找第几个童鞋的成绩?");
              int index=reader.nextInt();
                if(index>0&&index<=n)
                System.out.printfln("第"+index+"个童鞋的成绩是"+score[index+1]);
                else
                 System.out.println("对不起,您输入的数字有误!");
                    }


    }
搜索更多相关主题的帖子: static public double import 
2013-03-15 17:44
杨松松
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:98
专家分:142
注 册:2011-12-3
得分:0 
怎么没有人啊,救命啊
2013-03-15 17:53
chenfumig
Rank: 2
等 级:论坛游民
威 望:1
帖 子:12
专家分:12
注 册:2012-12-9
得分:0 
System.out.printfln("第"+index+"个童鞋的成绩是"+score[index+1]);
好像是println()的,打多了一个f。
2013-03-15 19:02
chenfumig
Rank: 2
等 级:论坛游民
威 望:1
帖 子:12
专家分:12
注 册:2012-12-9
得分:0 
System.out.print("请输入第"+(i+1)"个童鞋的成绩:");
("请输入第"+(i+1)+"个童鞋的成绩:");
好像少了一个连接符号+
2013-03-15 19:03
chenfumig
Rank: 2
等 级:论坛游民
威 望:1
帖 子:12
专家分:12
注 册:2012-12-9
得分:8 
package test;

import java.util.Scanner;

public class ScoreTest {
    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        double score[] = null;
        int n;
        System.out.println("您要输入多少个学生的成绩");
        n = reader.nextInt();
        if (n <= 0)
            System.out.println("个数错误!");
        else
            score = new double[n];
        for (int i = 0; i < n; i++) {
            System.out.print("请输入第" + (i + 1) + "个童鞋的成绩:");
            score[i] = reader.nextDouble();
        }
        Info.showInfo(n, score);

    }

    static class Info {
        public static void showInfo(int n, double score[]) {
            Scanner reader = new Scanner(System.in);
            System.out.println("您想查找第几个童鞋的成绩?");
            int index = reader.nextInt();
            if (index > 0 && index <= n)
                System.out.println("第" + index + "个童鞋的成绩是" + score[index + 1]);
            else
                System.out.println("对不起,您输入的数字有误!");
        }
    }

}

试试。不要用Tab键,用空格键。。。
2013-03-15 20:01
chenfumig
Rank: 2
等 级:论坛游民
威 望:1
帖 子:12
专家分:12
注 册:2012-12-9
得分:0 
好像是静态的问题。
2013-03-15 20:34
hhwz
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:87
帖 子:687
专家分:4502
注 册:2011-5-22
得分:4 
程序代码:
    public static void main(String[] args) {
        Scanner reader = new Scanner(System.in);
        double score[];
        int n;
        System.out.println("您要输入多少个学生的成绩");
        n = reader.nextInt();
        if (n <= 0) {
            System.out.println("个数错误!");
        } else {
            score = new double[n];
            for (int i = 0; i < n; i++) {
                System.out.print("请输入第" + (i + 1) + "个童鞋的成绩:");
                score[i] = reader.nextDouble();
            }
            showInfo(n, score);
        }
       


    }

    public static void showInfo(int n, double score[]) {
        Scanner reader = new Scanner(System.in);
        System.out.println("您想查找第几个童鞋的成绩?");
        int index = reader.nextInt();
        if (index > 0 && index <= n)
            System.out.println("第" + index + "个童鞋的成绩是" + score[index - 1]);
        else
            System.out.println("对不起,您输入的数字有误!");
    }
2013-03-16 13:52
淤泥
Rank: 2
等 级:论坛游民
帖 子:6
专家分:11
注 册:2013-1-5
得分:8 
import java.util.Scanner;
    public class ScoreTest{
        public static void main(String[] args){
            Scanner reader=new Scanner(System.in);
            double score[];
            int n;
            System.out.println("您要输入多少个学生的成绩");
            n=reader.nextInt();
            if(n<=0)
              System.out.println("个数错误!");
                 else
                         {
                          score=new double[n];
                   for(int i=0;i<n;i++){
                      System.out.print("请输入第"+(i+1)+"个童鞋的成绩:");
                      score[i]=reader.nextDouble();
                }
                Info info = new Info();
                  info.showInfo(n,score);  
              }               
            
    }
}
    class Info{
        public void showInfo(int n,double score[]){
            Scanner reader=new Scanner(System.in);
            System.out.println("您想查找第几个童鞋的成绩?");
              int index=reader.nextInt();
                if(index>0&&index<=n)
                System.out.println("第"+index+"个童鞋的成绩是"+score[index-1]);
                else
                 System.out.println("对不起,您输入的数字有误!");
      }


    }
2013-03-18 12:34
杨松松
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:98
专家分:142
注 册:2011-12-3
得分:0 
回复 8楼 淤泥
哦~~忘定义了
2013-03-20 08:36
杨松松
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:98
专家分:142
注 册:2011-12-3
得分:0 
回复 7楼 hhwz
我用你提供的代码试了一下,貌似不能正确执行啊
2013-03-20 08:37



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




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

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