入门客AI创业平台(我带你入门,你带我飞行)
博文笔记

OJ多组测试数据的输入(Java代码实现)

创建时间:2017-10-15 投稿人: 浏览次数:1372
Java:必须是public class Main提交,并且不能带包名,输入和输出的格式一定要按照题目要求的去写,否则提交不过。输入不可用文件输入。使用

Scanner sc=new Scanner(System.in);

1.  多组数据,每组数据一个n(5<= n <=10^6)。
接下来n个整数Xi (1<=Xi<=10^6)。

Sample Input 4
1 2 3 4
5 1 2 6 5 4 这种使用 while(sc.hasNext()){
          n=sc.nextInt();
          int a[]=new int [n];
          for(int i=0;i<n;i++){
                a[i]=sc.nextInt();
          }
}

2. 多组数据 input 5 20 30 40 每组是一个测试用例, int n; while(sc.hasNext()){
         n=sc.nextInt();
}
3. 一个n,加上一个大小为n的数组 input 2 sdfgdsg dgsfdg 使用: Scanner sc = new Scanner(System.in);  
int n = sc.nextInt();  
for(int i=0;i<n;i++){  
     String str = sc.next();  
     ......  
}  
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
  • 上一篇:没有了
  • 下一篇:没有了
未上传头像