首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

统计全班学生成绩,求相助修改一下,报错了

2013-12-04 
统计全班学生成绩,求帮助修改一下,报错了import java.util.*import java.io.*public class Tongxun{//St

统计全班学生成绩,求帮助修改一下,报错了
import java.util.*;
import java.io.*;
public class Tongxun
{
            //String info[][];
             
            public static void  display(String info[][])
            {
                int i;
                System.out.println("编号    姓名      性别       电话      通信地址");
                for(i=0;i<info.length;i++)
                      System.out.println(info[i][0]+"   "+info[i][1]+"   "+info[i][2]+"   "+info[i][3]+"   "+info[i][4]);
            }
          public static void  Input(String info[][])
              {
                      int i,tmp;
                      Scanner sc = new Scanner(System.in);
                      System.out.println("请输入您要添加的人的个数");
                        i=sc.nextInt();
                        sc.close();
                        System.out.println("请输入:姓名、性别、电话、通信地址,中间空格隔开");
                                  //这是用于获取键盘输入的方法
                      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                      String inputStr = null;
                        for (int j=0;j<i;j++)
                        {                            
                              //br.readLine():每当在键盘上输入一行内容按回车,刚输入的内容将被br读取到。
                              while ((inputStr = br.readLine()) != null)
                              {
                                  //将用户输入的字符串以逗号( )作为分隔符,分隔成个字符串
                                      String[] posStrArr = inputStr.split(" ");//拆分字符串
                                      tmp=j;
                                      info[j][0]= String.valueOf(tmp);
                                      for(int k=1;k<5;k++)
                                      {
                                           info[j][k]=posStrArr[k-1];                                          


                                      }
                                                         
                                  }                                                
                            }
                       
                  }
            public static void main(String[] args)
    {
                Tongxun t=new Tongxun();
                String Info[][]=new String[100][5];
                t.Input(Info[100][5]);
    }    
             
}E:\ming>javac Tongxun.java
Tongxun.java:47: 无法将 Tongxun 中的 Input(java.lang.String[][]) 应用于 (java.la
ng.String)
                t.Input(Info[100][5]);
                 ^
1 错误
,while ((inputStr = br.readLine()) != null)
                              {
                                  //将用户输入的字符串以逗号( )作为分隔符,分隔成个字符串
                                      String[] posStrArr = inputStr.split(" ");//拆分字符串
                                      tmp=j;
                                      info[j][0]= String.valueOf(tmp);
                                      for(int k=1;k<5;k++)
                                      {
                                           info[j][k]=posStrArr[k-1];                                          
                                      }
                                                         
                                  }      给我讲解一下这里,我不是很理解,怎么就把输入的信息都输入到info[j][k]里了


[解决办法]


package com.zhangqi.se;

import java.util.*;
import java.io.*;
public class Tongxue {
public static void  display(String info[][]) {
    int i;
    System.out.println("编号    姓名      性别       电话      通信地址");
    for(i=0;i<info.length;i++)
    System.out.println(info[i][0]+"   "+info[i][1]+"   "+info[i][2]+"   "+info[i][3]+"   "+info[i][4]);
}

// 注意異常捕獲
// 方法名,變量名小寫開始
public static void  input(String info[][]) throws IOException {
        int i,tmp;
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您要添加的人的个数");
        i=sc.nextInt();
        sc.close();
        System.out.println("请输入:姓名、性别、电话、通信地址,中间空格隔开");
        //这是用于获取键盘输入的方法
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String inputStr = null;
        for (int j=0;j<i;j++) {                            
             //br.readLine():每当在键盘上输入一行内容按回车,刚输入的内容将被br读取到。
             while ((inputStr = br.readLine()) != null) {
                  //将用户输入的字符串以逗号( )作为分隔符,分隔成个字符串
                  String[] posStrArr = inputStr.split(" ");//拆分字符串
                  tmp=j;
                  info[j][0]= String.valueOf(tmp);
                  for(int k=1;k<5;k++)
                  {
                       info[j][k]=posStrArr[k-1];                                          
                  }
              }                                                
        }
    }
    public static void main(String[] args) throws IOException {
        // Tongxue t=new Tongxue();
        String info[][]=new String[100][5];
        // Input方法為靜態(static)方法,可以直接調用,無需new 實例出來
        input(info);
        // Info[100][5] 已經具體到一個字符串了,不是數組了,傳Info就可以了
        // t.Input(Info[100][5]);
    }   
}

帮你把程序简单改了下,你看下,eclipse不知为何今天成繁体字了,没来得及调。希望可以帮到你。

热点排行