for (int i = 0; i < name.length; i++) {
if (name[i].equals(null)) {
System.out.print("用户名:");
name[i]=input.next();
break;
}else{
continue;
} }
解决方案 »
- 求教
- applet换个机器,不能正常显示,这是怎么回事?
- 请问 prepareStatement是不是必须至少带一个IN参数(就是说sql 中至少要有一个'?',然后把值传进去 )?
- 麻烦大虾们给我的作业改错?
- 菜鸟的java问题
- 哪位用过jtpai有什么学习资料吗?必有重谢!!!!!
- 这个程序有问题吗?没问题的话 怎么去掉黄线呢?
- 我用JB8生成了一个EXE,运行后为什么觉得不对?
- 关于JTable右键选取
- which type error can be detected at compile time? the regulation?
- 接口与抽象类的问题
- 问大家关于j2se的IO流的问题?
然后将注册信息用MAP存储,用户名作为KEY,值就是这个类
//不能让你的程序结束了。不然变量就重新初始化。之前数组中的值就没有了。
while(true){}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int card =0;
int []number = new int[5];
String judge ="";
int name2 = 0;
int name1 =0;
int password1= 0;
String[] name = new String [1000];
int[] password = new int [1000];
int choice =0;
do {
System.out.println("*****欢迎登陆奖客富翁系统*****");
System.out.println("\t\t1.注册");
System.out.println("\t\t2.登陆");
System.out.println("\t\t3.抽奖");
System.out.println("****************************");
System.out.print("请选择菜单:");
choice = input.nextInt();
switch (choice) {
case 1:
System.out.println("[奖客富翁系统>注册]");
System.out.println("请填写个人信息:");
for (int i = 0; i < name.length; i++) {
name1 = i;
if (name[i].equals(null)) {
System.out.print("用户名:");
name[i]=input.next();
break;
}
}
for (int j = 0; j < password.length; j++) {
password1 = j;
if(password[j]==0){
System.out.print("密码:");
password[j] = input.nextInt();
break;
}
}
System.out.println("\n注册成功,请您记住您的会员号");
System.out.println("用户名\t\t密码\t\t会员号");
System.out.println(name[name1]+"\t\t"+password[password1]+"\t\t"+((int)(Math.random()*9000+1000)));
break;
case 2:
System.out.print("请输入用户名:");
name[name1+1] = input.next();
for (int i = name1+1; i < name.length; i++) {
if (name[i].equals(name[name1])) {
name2 = i;
break;
}else{
System.out.print("用户名错误,请重新输入:");
name[i+1] =input.next();
}
}
System.out.print("请输入密码:");
password[password1+1] = input.nextInt();
for (int i = password1+1; i < password.length; i++) {
if (password[i]==password[password1]) {
break;
}else{
System.out.print("用户密码错误,请重新输入:");
password[i+1] =input.nextInt();
}
}
System.out.println("欢迎您:"+name2);
break;
case 3:
System.out.print("[奖客富翁系统>抽奖]");
System.out.print("请输入您的卡号");
card = input.nextInt();
System.out.print("本日的幸运数字为:");
for (int i = 0; i < number.length; i++) {
number[i] = (int)(Math.random()*9000+1000);
System.out.print("\t"+number[i]);
}
for (int i = 0; i < number.length; i++) {
if (number[i]==card) {
System.out.println("\n恭喜您成为本日的幸运会员");
break;
}
if (i==number.length-1) {
System.out.println("\n很抱歉!您不是本日的幸运会员");
}
}
break;
default:
break;
}
System.out.println("继续吗?(y/n)");
judge = input.next();
} while (judge.equalsIgnoreCase("y"));
System.out.println("系统退出谢谢使用");
}
}
name1 = i;
if (name[i].equals(null)) {
System.out.print("用户名:");
name[i]=input.next();
break;
}
为什么不对
if (name[i].equals(null))
改为
if (name[i]==null)
---------------------
2:
case 2 部分:查找用户名要从name[]的0位开始,
for (int i = name1+1; i < name.length; i++)
改为
for (int i =0; i < name.length; i++)
-----------------
if (name[i].equals(name[name1])) {
name2 = i;
break;
}else{
System.out.print("用户名错误,请重新输入:");
name[i+1] =input.next();
}
//改为
if (name[i].equals(name[name1])) {
name2 = i;
break;
}
if (i == name.length - 1) {
System.out.print("用户名错误,请重新输入:");
name[i + 1] = input.next();
}
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
public class Client {
public static void main(String[] args) throws Exception {
launch();
}
public static void launch() throws Exception {
boolean exit = false;
Map<String,User> reg = new HashMap<String,User>();
while(!exit) {
System.out.println("****欢迎进入奖客富翁系统*****");
System.out.println(" 1.注册");
System.out.println(" 2.登陆");
System.out.println(" 3.抽奖");
System.out.println("****************************");
System.out.print("请选择菜单:");
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
String option = read.readLine();
option = option.replaceAll(" |\t", "");
System.out.println();
if("1".equals(option) || "2".equals(option) || "3".equals(option)) {
if("1".equals(option)) {
register(reg);
} else if("2".equals(option)) {
login(reg);
} else {
lottery();
}
}
System.out.print("继续吗?(y/n):");
read = new BufferedReader(new InputStreamReader(System.in));
option = read.readLine();
option = option.replaceAll(" |\t", "");
if("y".equals(option)) {
System.out.println();
System.out.println();
} else {
System.out.println("系统推出,谢谢使用!");
exit = true;
}
}
}
private static void register(Map<String,User> reg) throws Exception {
String username = "";
String password = "";
String cardno = "";
System.out.println("[奖客富翁系统 > 注册]");
System.out.println("请填写个人注册信息");
System.out.print("用户名:");
BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
username = strin.readLine();
username = username.replaceAll(" |\t", "");
System.out.print("密 码:");
strin = new BufferedReader(new InputStreamReader(System.in));
password = strin.readLine();
password = password.replaceAll(" |\t", "");
cardno = String.valueOf(Math.round(1000 + Math.random() * 8999));
System.out.println("注册成功,请记好您的会员卡号");
System.out.format("%-6s\t%-10s"+"会员卡号","用户名","密码");
System.out.println();
System.out.format("%-6s\t%-10s"+cardno,username,password);
System.out.println();
User user = new User();
user.setUsername(username);
user.setPassword(password);
user.setCardno(cardno);
reg.put(username, user);
}
private static void login(Map<String,User> reg) throws Exception {
String username = "";
String password = "";
System.out.println("[奖客富翁系统 > 登录]");
System.out.print("请输入用户名:");
BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
username = strin.readLine();
username = username.replaceAll(" |\t", "");
System.out.print("请输入密 码:");
strin = new BufferedReader(new InputStreamReader(System.in));
password = strin.readLine();
password = password.replaceAll(" |\t", "");
User user = reg.get(username);
if(user == null) {
System.out.println("您输入的用户名还没注册!");
return;
} else {
if(!password.equals(user.getPassword())) {
System.out.println("您输入的密码有误!");
return;
} else {
System.out.println("欢迎您," + username);
}
}
}
private static void lottery() {
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
public class Client {
public static void main(String[] args) throws Exception {
launch();
}
public static void launch() throws Exception {
boolean exit = false;
Map<String,User> reg = new HashMap<String,User>();
while(!exit) {
System.out.println("****欢迎进入奖客富翁系统*****");
System.out.println(" 1.注册");
System.out.println(" 2.登陆");
System.out.println(" 3.抽奖");
System.out.println("****************************");
System.out.print("请选择菜单:");
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
String option = read.readLine();
option = option.replaceAll(" |\t", "");
System.out.println();
if("1".equals(option) || "2".equals(option) || "3".equals(option)) {
if("1".equals(option)) {
register(reg);
} else if("2".equals(option)) {
login(reg);
} else {
lottery();
}
}
System.out.print("继续吗?(y/n):");
read = new BufferedReader(new InputStreamReader(System.in));
option = read.readLine();
option = option.replaceAll(" |\t", "");
if("y".equals(option)) {
System.out.println();
System.out.println();
} else {
System.out.println("系统推出,谢谢使用!");
exit = true;
}
}
}
private static void register(Map<String,User> reg) throws Exception {
String username = "";
String password = "";
String cardno = "";
System.out.println("[奖客富翁系统 > 注册]");
System.out.println("请填写个人注册信息");
System.out.print("用户名:");
BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
username = strin.readLine();
username = username.replaceAll(" |\t", "");
System.out.print("密 码:");
strin = new BufferedReader(new InputStreamReader(System.in));
password = strin.readLine();
password = password.replaceAll(" |\t", "");
cardno = String.valueOf(Math.round(1000 + Math.random() * 8999));
System.out.println("注册成功,请记好您的会员卡号");
System.out.format("%-6s\t%-10s"+"会员卡号","用户名","密码");
System.out.println();
System.out.format("%-6s\t%-10s"+cardno,username,password);
System.out.println();
User user = new User();
user.setUsername(username);
user.setPassword(password);
user.setCardno(cardno);
reg.put(username, user);
}
private static void login(Map<String,User> reg) throws Exception {
String username = "";
String password = "";
System.out.println("[奖客富翁系统 > 登录]");
System.out.print("请输入用户名:");
BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
username = strin.readLine();
username = username.replaceAll(" |\t", "");
System.out.print("请输入密 码:");
strin = new BufferedReader(new InputStreamReader(System.in));
password = strin.readLine();
password = password.replaceAll(" |\t", "");
User user = reg.get(username);
if(user == null) {
System.out.println("您输入的用户名还没注册!");
return;
} else {
if(!password.equals(user.getPassword())) {
System.out.println("您输入的密码有误!");
return;
} else {
System.out.println("欢迎您," + username);
}
}
}
private static void lottery() {
}
}