当前位置: 代码迷 >> J2SE >> 调用Scanner向数组中新增元素,该如何解决
  详细解决方案

调用Scanner向数组中新增元素,该如何解决

热度:101   发布时间:2016-04-24 12:13:04.0
调用Scanner向数组中新增元素
我写的代码。运行到所有元素输入完之后就没动静了,要么就抛异常,请大大们帮我看一下,谢谢

Java code
package Community;import java.util.Scanner;import User.DbStore;public class temp {    public static void main(String args[])    {        DbStore abcd = new DbStore();                Scanner scan = new Scanner(System.in);                System.out.println("请输入小区编号:");        String id = scan.next();        System.out.println("请输入小区名称:");        String name = scan.next();        System.out.println("请输入小区经理:");        String manager = scan.next();        System.out.println("请输入所在区域:");        String area = scan.next();        System.out.println("请输入小区状态:");        String statue = scan.next();        System.out.println("请输入渗透率:");        double Permeability = scan.nextDouble();        System.out.println("请输入覆盖用户数:");        int userCount = scan.nextInt();                int last = abcd.getCommArr().length+1;                abcd.getCommArr()[last].setCommId(id);        abcd.getCommArr()[last].setCommName(name);        abcd.getCommArr()[last].setCommManager(manager);        abcd.getCommArr()[last].setCommArea(area);        abcd.getCommArr()[last].setCommStatue(statue);        abcd.getCommArr()[last].setPermeability(Permeability);        abcd.getCommArr()[last].setUserCount(userCount);                System.out.println("新增成功!");        System.out.println("该社区信息如下:"+"\n");        System.out.println("小区编号"+"\t\t"+"小区名称"+"\t\t"+"小区经理"+"\t\t"+"区域"+"\t\t"+"小区状态"+"\t\t"+"渗透率"+"\t\t"+"覆盖用户数");        System.out.println("----------------------------------------------------------------------");        System.out.println(abcd.getCommArr()[last].getCommId()+"\t\t"+abcd.getCommArr()[last].getCommName()+"\t\t"+abcd.getCommArr()[last].getCommManager()+"\t\t"+abcd.getCommArr()[last].getCommArea()+"\t\t"+abcd.getCommArr()[last].getCommStatue()+"\t\t"+abcd.getCommArr()[last].getPermeability()+"%"+"\t\t"+abcd.getCommArr()[last].getUserCount());    }}


------解决方案--------------------
你代码没有贴完整,无法帮你调试
------解决方案--------------------
Java code
新增元素不能这么写的...public  static int[] add(int[] arr,int b)    {        int[] c = new int[arr.length+1];        for(int i=0;i<arr.length;i++)        {            c[i]=arr[i];        }        c[arr.length] = b;        return c;    }
  相关解决方案