51 lines
1.0 KiB
Java
51 lines
1.0 KiB
Java
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");
|
||
}
|
||
}
|
||
|
||
}
|
||
|