1.
package weekends_8;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
/*
* 1:获取10个1-20之间的随机数,要求不能重复
* */
public class RandomDemo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
ArrayList<Integer> al=new ArrayList<Integer>();
Random ran=new Random();
while(true) {
int num=ran.nextInt(21);
if(!al.contains(num)&&num!=0) {
al.add(num);
}
if(al.size()>=10) {
System.out.println(al);
break;
}
}
}
}
```![这里写图片描述](http://img.blog.csdn.net/20171115124358427?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvVFVfQk8=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
2.
<div class="se-preview-section-delimiter"></div>
这里写代码片
“`
package weekends_8;
import java.util.ArrayList;
import java.util.Scanner;
/*
* 键盘录入多个数据,以0结束,要求在控制台输出这多个数据中的最大值
* */
public class EndWith0 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
ArrayList<Integer> al=new ArrayList<Integer>();
while(true) {
System.out.println("请输入一个数据");
int a=sc.nextInt();
if(a!=0) {
al.add(a);
continue;
}break;
}
int temp=0;
for(Integer s:al) {
if(s>temp) {
temp=s;
}
}
System.out.println("你输入的最大数据为"+temp);
}
}