Files
javaSE-0113/day04/src/com/inmind/method01/Demo02.java
2026-01-16 15:08:48 +08:00

51 lines
1.0 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.inmind.method01;
public class Demo02 {
public static void main(String[] args) {
boolean result = isEqual(4, 4);
System.out.println(result);
int lh = getLH(10);
System.out.println(lh);
printN(5);
}
//案例1比较两个整数是否相同
public static boolean isEqual(int a,int b){
//实现一
/*if (a == b) {
return true;
} else {
return false;
}*/
//实现二
/*boolean result = a==b? true:false;
return result;*/
// return a==b? true:false;
//实现三
return a==b;
}
//案例2运算1到n的累和
public static int getLH(int n) {
int result = 0;//累和
for (int i = 0; i <= n; i++) {
result += i;
}
return result;
}
//案例3打印n遍HelloWorld.
public static void printN(int n){
for (int i = 0; i < n; i++) {
System.out.println("helloWorld");
}
}
}