标签:public 报错 -- private 就会 input rgs void while
package com.java.Day20161118;
//编一个多用户登陆程序
import java.util.*;
public class Login {
private static String [] names ={"user", "admin" , "manager"} ;
private static String [] password = {"123123","asdfg","123456"};
private static int index = -1 ;
public static void main(String[] args) {
Scanner input = new Scanner(System.in) ;
do{
System.out.println("请输入用户名:");
String name = input.next() ;
for (int i = 0; i < names.length; i++) {
if (name.equals(names[i])) { //为什么用name==names[i] 就会报错 ?
index = i ;
break ;
}
}
}while(index==-1);
System.out.println();
System.out.println("请输入密码:");
int index2 = -2 ;
int index3 = 3 ;//用来记录剩余登陆次数。
do{
System.out.println();
String pass = input.next();
System.out.println();
if (pass.equals(password[index])) {
System.out.println();
System.out.println("进入主菜单!");
index2 = -4 ;
}else{
index3 -- ;
if(index3==0){
System.out.println("输入密码有误,请明日再来登陆!");
break ;
}
System.out.println("输入的密码有误,请重新输入:");
System.out.println("您还有"+index3+"次机会!");
}
}while(index2 ==-2);
}
}
标签:public 报错 -- private 就会 input rgs void while
原文地址:http://www.cnblogs.com/ljwa/p/6081120.html