发布网友 发布时间:2022-04-21 16:24
共1个回答
热心网友 时间:2023-11-15 08:23
import java.util.Scanner;
public class Program1 {
public static void main(String[] args) {
Scanner i = new Scanner(System.in);
int a = i.nextInt();
int b = i.nextInt();
if (a > 100 || a < 10 || b>100 ||b<10) {
System.out.println("输入错误,请输入两位数!");
}else{
System.out.println(a + b);
}
}
}
java的用法小结
一、简单的stream,parallelStream慎用
List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8);
list.parallelStream().forEach(System.out::println);
list.parallelStream().forEachOrdered(System.out::println);
二、简单的stream, collect, sum, count,
1、取某一字段 stream & collect
System.out.println(userList.stream().map(User::getAddress).collect(Collectors.toList()));
System.out.println("---------");
ArrayList<String> arrayList =
userList.stream().map(User::getAddress).collect(Collectors.toCollection(ArrayList::new));
System.out.println(arrayList);
System.out.println("---------");
System.out.println(userList.stream().map(User::getAddress).collect(Collectors.joining("@@")));
2、取总和 sum
System.out.println(userList.stream().mapToInt(User::getAge).sum());
3、分组
Map<String, List<User>> addressMap =
userList.stream().collect(Collectors.groupingBy(User::getAddress));
System.out.println(addressMap);