當(dāng)前位置:
首頁(yè) >
prictice
發(fā)布時(shí)間:2023/12/10
49
豆豆
package cn.cast.collection;import java.util.*;/*** @author zhangyu* @date 2021年08月29日 7:43 下午* 泛型:jdk中的泛型為偽泛型* 在編譯時(shí)期有效,解決安安全問(wèn)題*/
public class test {public static void main(String[] args) {
// ArrayList<String> arr = new ArrayList();
// arr.add("123kahfkadfhkdh");
// arr.add("234");
// Iterator<String> it = arr.iterator();
// while (it.hasNext()){
// System.out.println(it.next().length());
// }method_2();}//隨機(jī)產(chǎn)生10個(gè)整數(shù),要求不重復(fù)public static void method_1(){//創(chuàng)建Random類(lèi)Random number = new Random();//創(chuàng)建集合List<Integer> list = new ArrayList<>();while (true){//獲取隨機(jī)數(shù)int num = number.nextInt(20)+1;if(!list.contains(num)){list.add(num);if(list.size()==10){break;}}}System.out.println(list);}//從鍵盤(pán)錄入任意個(gè)數(shù)據(jù),以0 結(jié)束,要求輸出時(shí)輸出錄入數(shù)據(jù)中最大的值public static void method_2(){System.out.println("start:");Scanner sc = new Scanner(System.in);List<Integer> list = new ArrayList<>();while (true){System.out.println("PLEASE ADD NUMBER:");int n = sc.nextInt();if(n==0){int s = 0;System.out.println("print the max number");for(int x = 0;x<list.size();x++){if(s<list.get(x)){s=list.get(x);System.out.println("the max number is : "+s);}}break;}else{System.out.println("Add success!");list.add(n);}}}}
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)
總結(jié)
- 上一篇: 斗鱼上市,直播圈“战火”再起,海店湾:狭
- 下一篇: gc就是fullgc吗 major_线上