三次密码登录,错误就退出,写于20180626记于20180630

package tst;


import java.util.Scanner;


public class tst {


/**
* @param args
*/
    private static int cnt = 0;


    private final static String key = new String("aabb");
    
public static void main(String[] args) {
// TODO Auto-generated method stub
        while ( true ) {
       
            Scanner sc = new Scanner(System.in); //java的输入函数
            String str =  sc.nextLine();
            System.out.println("str :" + str);  //java的 print()没有换行符  ,println() 自动换行
            
            if ( str.equals( key ) ) {
            System.out.println("You are login in");
            Scanner scInt = new Scanner(System.in); //也可以直接用sc.nextLine()即可
            int getVal = scInt.nextInt();
            System.out.println("getVal : " +getVal);
            Run( getVal ); //函数调用,刚学会不久
            break; //跳出 循环
            } else {    // 输错了
            cnt = cnt + 1;
            System.out.println("Please try again!");
            if ( cnt >= 3 ) {
            System.out.println("You have been input three times wrong keyword");
            break;
            }
            continue;
            }
        }
}
private static final void Run ( int in ) {
System.out.println("Run"); //实现一个矩阵乘法
int get = in;
int outMult;
for ( int i = 1; i < get; i++ ) {
for ( int j = 1; j < get; j++ ) {
outMult = i * j;
System.out.print(outMult + "     ");
}
System.out.println(); //打印一个换行符
}
}

}


不想截图了:

运行结果:

aabb
str :aabb
You are login in
5
getVal : 5
Run
1     2     3     4     
2     4     6     8     
3     6     9     12     
4     8     12     16     

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值