package com.sxt;
public class TestLoop {
public static void main(String[] args) {
for(int m=1;m<=5;m++){
for(int i=0;i<5;i++) {
System.out.println(m+"\t");
}
System.out.println();
}
}
}
1
1
1
1
1
2
2
2
2
2
3
3
3
3
3
4
4
4
4
4
5
5
5
5
5
package com.sxt;
public class TestLoop {
public static void main(String[] args) {
// for(int m=1;m<=5;m++){
// for(int i=0;i<5;i++) {
// System.out.println(m+" ");
// }
// System.out.println();
// }
for(int m=1;m<=9;m++) {
for(int n=1;n<=m;n++) {
System.out.println(n+""+m+"="+(nm)+"\t");
}
System.out.println();
}
}
}
1*1=1
12=2 22=4
13=3 23=6 3*3=9
14=4 24=8 34=12 44=16
15=5 25=10 35=15 45=20 5*5=25
16=6 26=12 36=18 46=24 56=30 66=36
17=7 27=14 37=21 47=28 57=35 67=42 7*7=49
18=8 28=16 38=24 48=32 58=40 68=48 78=56 88=64
19=9 29=18 39=27 49=36 59=45 69=54 79=63 89=72 9*9=81
package com.sxt;
public class TestBreak {
public static void main(String[] args) {
int total=0;
while(true) {
total++;
int i=(int)(Math.random()*100);
System.out.println(i);
if(i==88) {
break;
}
}
System.out.println("循环次数:"+total);
}
}
54
49
59
10
38
29
70
18
11
63
98
5
85
52
99
20
81
72
43
51
19
20
41
38
88
循环次数:25
package com.sxt;
public class TestMethod {
public static void main(String[] args) {
//sayLoveU();
add(10,20,30);
add(100,200,300);
}
public static void sayLoveU() {
System.out.println("I love you!");
System.out.println("我爱你!");
System.out.println("520!");
}
public static int add(int a,int b,int c) {
int sum=a+b+c;
System.out.println("sum:"+sum);
return sum;//return两个作用:返回值,结束方法运行
}
}
sum:60
sum:600
package com.sxt;
public class Test22 {
public static void main(String[] args) {
long result=factorial(5);
System.out.println(result);
}
public static long factorial(int n) {
if(n==1) {
return 1;
}else {
return n*factorial(n-1);
}
}
}
120
package com.sxt;
public class Test22 {
public static void main(String[] args) {
long startTime=System.currentTimeMillis();
long result=factorial(5);
long endTime=System.currentTimeMillis();
System.out.println(result);
System.out.println("递归耗时:"+(endTime-startTime));
}
public static long factorial(int n) {
if(n==1) {
return 1;
}else {
return n*factorial(n-1);
}
}
}
120
递归耗时:0