蓝桥杯2015培训(4)

流程图

起止符号圆角矩形

流程符号箭头

输入输出平行四边形

处理     矩形

决策判断菱形

连接     圆

多分支结构

switch(表达式)

{

  case常量:代码块 break;

  case常量:代码块 break;

case 常量:代码块 break;

default :代码块 break;

}

额外知识:JDK 利用switch时,如果需要判断字符串,则需要安装JDK1.7

 

循环

1. for循环

for(参数初始化;条件判断;更新循环变量)

{

循环操作;

}

执行循环操作

for循环执行步骤

           1.参数初始化

         2.条件判断

           3.循环操作

           4.更新循环变量

2.  import java.util.Scanner;

3.  class LT05

4.  {

5.  public static void main(String[] args)

6.  {

7.   

8.       int begin = 1;

9.   Scanner sc  = new Scanner(System.in);

10.                        int num = sc.nextInt();

11.                        int temp = 0;

12.                        int count = 0;

13.                        

14.                        if((num % 2 )== 1)

15.                          {

16.                                  while(count != num)

17.                                    {

18.                                     temp = num - begin/2;

19.                                     for(int i = 0; i < temp; i++ )

20.                                       {

21.                                           System.out.print(" ");

22.                                       }

23.                                     for(int i = 0; i < begin; i++)

24.                                       {

25.                                           System.out.print("*");

26.                                       }

27.                                            System.out.println();

28.                                            count ++;

29.                                            if(count>= num/2 + 1)

30.                                             {

31.                                                     begin  -= 2;

32.                                             }

33.                                             else

34.                                             {

35.                                                      begin += 2;

36.                                             }

37.                            

38.                                            

39.                                    }

40.               

41.                          }else System.out.println("错误的输入");

42.               

43.                        

44.               

45.                       }

46.              }

public class A1_1000sum {

 

   public static void main(String[] args) {

     // TODO Auto-generated method stub

       int sum = 0;

       for(int i = 0;i<1000;i++)

       {

         if(i%2 != 0)

         {

           sum += i;

         }

       }

       System.out.println(sum);

   }

 

47.              }

 

2.while循环

   while(循环条件)

{

循环代码块

}

class LT13

{

         public static void main(String[] args)

         {

                   int i = 0;

                   int j = 0;

                   while(j<10)

                   {

           System.out.print("*");

                      i++;

                      if(i>j)

                            {

                               j++;

                               i = 0;

                               System.out.println();

                       }

                   }

         }

}

 

 

3.do while循环

do

{

循环代码块

}while(循环条件);

import java.util.Scanner;

class Test002

{

         final  static String PASSWORD = "12345";

         public static void main(String[] args)

         {

                   Scanner input = new Scanner(System.in);

                   System.out.println("输入用户名");

                   String usrName = input.next();

                   String pas = "";

                   do{

                            System.out.println("请输入密码");

                            pas = input.next();

                            System.out.println("猜猜你的密码是否正确");

                   }while(!pas.equals(PASSWORD));

                   System.out.println("login success!");

         }

}

 

九九乘法表

public class NineNine {

 

   public static void main(String[] args) {

     // TODO Auto-generated method stub

        int i = 1;

        int j = 1;

        System.out.println("99乘法表");

        for(;i<10;i++)

        {

        for(j = 1;j<=i;j++)

            System.out.print(i+"*"+j+"="+i*j+"\t");

        System.out.println();

        }

       

   }

 

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值