






int[] sales = new int[]{16, 26, 36, 6, 100};
int result = 0;
for(int i=0; i<sales.length; i++){
result += sales[i];
}
System.out.println(result);

private int getMax(int[] array){
int max = array[0];
for (int i = 0; i < array.length; i++) {
if (array[i]>max){
max = array[i];
}
}
return max;
}

Random rd = new Random();
Scanner sc = new Scanner(System.in);
int[] randoms = new int[5];
for (int i = 0; i < randoms.length; i++) {
randoms[i] = rd.nextInt(20 + 1);
}
boolean flag = false;
for(;;){
System.out.println("请输入数据:");
int guessNumber = sc.nextInt();
for (int i = 0; i < randoms.length; i++) {
if (guessNumber==randoms[i]){
flag = true;
break;
}
}
if (flag){
break;
}
}
System.out.println("您猜中了");
System.out.println("生成的随机数为:");
System.out.println(Arrays.toString(randoms));

switch





求1到10 的奇数和
int result = 0;
for(int i = 1; i <= 10; i++){
if(i % 2 == 1) {
result += i;
}
}
同时还要知道水仙花数的个数

int count = 0;
for(int i=100; i<=999; i++){
int ge = i % 10;
int shi = i / 10 % 10;
int bai = i / 100;
if(Math.pow(ge, 3) + Math.pow(shi, 3) + Math.pow(bai, 3) == i){
//其中这个==进行了自动类型转换
count++;
System.out.println(i);
}
}
System.out.println(count);



double thickness = 0.1;
double HEIGHT = 8848.8 * 1000;
int count = 0;
while(thickness < HEIGHT){
thickness *= 2;
count++;
}
System.out.println(count);



String password = "123456";
Scanner sc = new Scanner(System.in);
for(;;){
System.out.println("请输入密码");
String userInput = sc.next();
if(userInput.equals(password)){
System.out.println("成功进入系统");
break;
}else{
System.out.println("密码输入错误请重试。。。");
}
}
注意字符串判断相等是使用 .equals
类型转换
自动类型转换
类型范围小的变量可以赋值给范围类型大的变量

表达式的自动类型提升


基本运算符


加符号做连接符

而python 不能够 字符串和整型相加,可以通过python的.format



直接写一个变量不是语句


赋值运算符

关系运算符


逻辑运算符


三元运算符
一行求三个数中最大值
System.out.println(i>j?(i>k?i:k):(j>k?j:k));
优先级问题

