prictice

package cn.cast.collection;import java.util.*;/*** @author zhangyu* @date 2021年08月29日 7:43 下午* 泛型:jdk中的泛型为伪泛型* 在编译时期有效,解决安安全问题*/
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();}//随机产生10个整数,要求不重复public static void method_1(){//创建Random类Random number = new Random();//创建集合List<Integer> list = new ArrayList<>();while (true){//获取随机数int num = number.nextInt(20)+1;if(!list.contains(num)){list.add(num);if(list.size()==10){break;}}}System.out.println(list);}//从键盘录入任意个数据,以0 结束,要求输出时输出录入数据中最大的值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);}}}}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/421769.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

NetworkOnMNetworkOnMainThreadException

这个异常大概意思是在主线程访问网络时出的异常。 Android在4.0之前的版本 支持在主线程中访问网络&#xff0c;但是在4.0以后对这部分程序进行了优化&#xff0c;也就是说访问网络的代码不能写在主线程中了。 用多线程可解决&#xff1a; 1 new Thread(){ 2 …

实现注册登录

package com.logein;/*** author alina* date 2021年09月15日 10:49 下午* User类&#xff0c;封装用户信息的类*/ public class User {//保存用户名private String username;//保存用户密码private String passwoer;public User() { }public User(String username,String pass…

字符串循环同构的最小表示法(转)

循环字符串的最小表示法的问题可以这样描述&#xff1a; 对于一个字符串S&#xff0c;求S的循环的同构字符串S’中字典序最小的一个。 由于语言能力有限&#xff0c;还是用实际例子来解释比较容易&#xff1a;设Sbcad&#xff0c;且S’是S的循环同构的串。S’可以是bcad或者cad…

(JAVA)set

package cn.cast.collection;import java.util.HashSet; import java.util.Iterator; import java.util.Set;/*** author Alina* date 2021年09月16日 11:08 下午* Set 接口派系特点* 不允许存储重复元素* 无序集合&#xff0c;不保证迭代顺序* 没有索引** Set集合迭代方式…

EM Algorithm

(From yesterday to now, I have learning EM for 4 times, and each time I will gain some new ideas and correct some misunderstandings. So cool!) Finally knows that the P(x(i),z(i);θ) means the joint distribution of x and z, parametered by θ. Only if the ta…

(JAVA)hashcode

package cn.cast.collection;/*** author Alina* date 2021年09月19日 8:00 下午* 对象的哈希值* 1.JAVA中&#xff0c;每一个类&#xff0c;都有一个十进制数的哈希值* 2.十进制数&#xff0c;叫做这个对象的哈希值* 3.class Object(){* public native int hashCode();* …

(JAVA)红黑树之自然顺序排序和自定义排序方式

package cn.book.objectarr;/*** author alina* date 2021年08月22日 6:57 下午*/ public class Student implements Comparable<Student> {private String name;private int age;public Student(){}/***** author Alina* date 2021/9/21 9:41 下午* param o* return int…

(JAVA)TreeSet

package homework;/*** author Alina* date 2021年09月22日 10:34 下午*/ class SetTestStudent implements Comparable<SetTestStudent>{private String name;private int gradeScoresOfChinese;private int gradeScoresOfMath;private int gradeScoresOfEnglish;public…

开始

纠结的考试终于结束了。。。可以静下心来整理博客了。。。转载于:https://www.cnblogs.com/Happyhe/archive/2013/05/29/3107121.html

(JAVA)Map集合

package map.demo;import java.util.*;/*** author Alina* date 2021年09月25日 11:20 下午* 底层原理是哈希表&#xff0c;保证唯一性* 允许存储null键&#xff0c;null值* 线程不安全&#xff0c;运行速度快* keyset()可以获取到键* Collections 类的方法reverseOrder :调用空…

各种推荐资料汇总。。。

http://blog.csdn.net/lzt1983/article/details/7914536 转载于:https://www.cnblogs.com/tandychao/archive/2013/05/30/3108022.html

(JAVA)File类

package filedemo;import java.io.File; import java.io.IOException;/*** author Alina* date 2021年10月07日 10:33 下午* File类 提供方法操作 文件 目录 文件夹* 1.两个静态成员变量 static String pathSeparator 路径分隔符* 2.static String separator 名称分隔符* 3.创…

(JAVA)File类2

package filedemo;import java.io.File; import java.io.FileFilter; import java.text.DateFormat; import java.util.Date;/*** author Alina* date 2021年10月10日 11:15 下午* 1.获取文件最后修改时间 Long lastModified()* 2.以数组获取路径下所有文件String[] list();Fi…

MVVM之旅

MVVM的概念已经在脑子里渗透了一段时间&#xff0c;也试着使用了一段时间&#xff0c;就我个人理解&#xff0c;MVVM所倡导的应该是解耦UI跟数据打交道的那一部分&#xff0c;而纯UI的还是写在CodeBehind里。MVVM是以绑定&#xff08;绑定数据、绑定命令&#xff09;来驱动的&a…