首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

初学者提问

2012-04-11 
菜鸟提问怎样控制字符串的输入?(现在不知道要输入多少个字符串,数量由自己控制)[解决办法]Java codepublic

菜鸟提问
怎样控制字符串的输入?(现在不知道要输入多少个字符串,数量由自己控制)

[解决办法]

Java code
public static void main(String[] args) {    try{    int a = 0;    Scanner scanner = new Scanner (System.in);    System.out.println("输入字符串个数是?:");    a = scanner.nextInt();        for (int n = 0; n <a; n++) {        String temp = scanner.nextLine();        System.out.println("第" + (n+1) +"字符串是?:" + temp);          }    catch(Exception e){        System.out.println("输入错误");            }    } 

热点排行