美文网首页
for循环几个小例子

for循环几个小例子

作者: 窦常荣 | 来源:发表于2018-08-13 20:55 被阅读0次

public class Try {

publicstaticvoidmain(String[]args) {

/**

*@author  dcr

*/

for(inta= 1;a<=5;a++) {

    for(intb= 0;b<= 4;b++) {

        System.out.print(a+"  ");

        }

        System.out.println();

}

System.out.println("*****************************");

for(inta= 1;a<=9;a++) {

    for(intb= 1;b<=9;b++) {

        System.out.print(a+"*"+b+"="+ (a*b) +"\t");

        }

        System.out.println();

}

System.out.println("*****************************");

for(intn= 1;n<=9;n++) {

    for(intm= 1;m<=n;m++) {

        System.out.print(n+"*"+m+"="+ (m*n)  +"\t");

        }

        System.out.println();

}

System.out.println("*****************************");

intf= 0;

intt= 0;

for(intq= 0;q<=100;q++) {

      if(q%2==0) {

               f=f+q;

      }else{

               t+=q;

       }

}

System.out.println("偶数和:"+f);

System.out.println("奇数和:"+t);

System.out.println("*****************************");

intr= 0;

into= 0;

intz= 1;

while(z<101) {

    if(z%2 == 0) {

        r+=z;

    }else{

        o+=z;

}

z++;

}

System.out.println("偶数和:"+r);

System.out.println("奇数和:"+o);

intw=0;

inth=1;

while(w<1001) {

    if(w> 0 && (w-1)%25 == 0) {

        System.out.println();

    }

if(w> 0 &&w%5 == 0) {

    System.out.print(w+"\t");

}

    w++;

        }

    }

}

实现效果:

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   

*****************************

1*1=1 1*2=2 1*3=3 1*4=4 1*5=5 1*6=6 1*7=7 1*8=8 1*9=9

2*1=2 2*2=4 2*3=6 2*4=8 2*5=10 2*6=12 2*7=14 2*8=16 2*9=18

3*1=3 3*2=6 3*3=9 3*4=12 3*5=15 3*6=18 3*7=21 3*8=24 3*9=27

4*1=4 4*2=8 4*3=12 4*4=16 4*5=20 4*6=24 4*7=28 4*8=32 4*9=36

5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 5*6=30 5*7=35 5*8=40 5*9=45

6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36 6*7=42 6*8=48 6*9=54

7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49 7*8=56 7*9=63

8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64 8*9=72

9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81

*****************************

1*1=1

2*1=2 2*2=4

3*1=3 3*2=6 3*3=9

4*1=4 4*2=8 4*3=12 4*4=16

5*1=5 5*2=10 5*3=15 5*4=20 5*5=25

6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36

7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49

8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64

9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81

*****************************

偶数和:2550

奇数和:2500

*****************************

偶数和:2550

奇数和:2500

5 10 15 20 25

30 35 40 45 50

55 60 65 70 75

80 85 90 95 100

105 110 115 120 125

130 135 140 145 150

155 160 165 170 175

180 185 190 195 200

205 210 215 220 225

230 235 240 245 250

255 260 265 270 275

280 285 290 295 300

305 310 315 320 325

330 335 340 345 350

355 360 365 370 375

380 385 390 395 400

405 410 415 420 425

430 435 440 445 450

455 460 465 470 475

480 485 490 495 500

505 510 515 520 525

530 535 540 545 550

555 560 565 570 575

580 585 590 595 600

605 610 615 620 625

630 635 640 645 650

655 660 665 670 675

680 685 690 695 700

705 710 715 720 725

730 735 740 745 750

755 760 765 770 775

780 785 790 795 800

805 810 815 820 825

830 835 840 845 850

855 860 865 870 875

880 885 890 895 900

905 910 915 920 925

930 935 940 945 950

955 960 965 970 975

980 985 990 995 1000

inth= (int)(Math.random() * 6);

System.out.println(h);

switch (h)

{

case1:

System.out.println(h+"first");

break;

case2:

System.out.println(h+"second");

break;

case3:

System.out.println(h+"theard");

break;

case4:

System.out.println(h+"fourth");

break;

default:

System.out.println("NON");

break;

}

相关文章

网友评论

      本文标题:for循环几个小例子

      本文链接:https://www.haomeiwen.com/subject/pgihsftx.html