public class member {? ? ?public String phone;? ? ?public String pass;? ? ?? ? ?public member(){}? ? ?public member(String phone,String pass)? ? ?{? ? this.phone=phone;? ? this.pass=pass;? ? ?}}import java.util.HashSet;import java.util.Set;public class people {? ?public String phone;? ?public String pass;? ?public Set<member> members;? ?? ?public people(String phone,String pass)? ?{ ? this.phone=phone; ? this.pass=pass; ? this.members=new HashSet<member>();? ?}}import java.util.ArrayList;import java.util.Arrays;import java.util.List;import java.util.Scanner;import org.omg.CORBA.PUBLIC_MEMBER;public class test {? ? public static List<member> gaMembers;? ??? ? public test()? ? {? ? this.gaMembers=new ArrayList<member>();? ? }? ??? ? public void add()? ? {? ? member m1=new member("111", "123");? ? gaMembers.add(m1);? ? ? ? member[] m2={new member("qqq", "qqw"),new member("wo", "gjj")};? ? gaMembers.addAll(Arrays.asList(m2));? ? ? ? ? ? ? ? }? ??? ???? ? public void foreach()? ? {? ? for(member mc:gaMembers)? ? {? ? System.out.println("會(huì)員信息:"+mc.phone+" , "+mc.pass);? ? }? ? }? ??? ?? ?? ??? ? public static void main(String[] args) { test t1=new test(); t1.add(); people p1=new people("1", "x小明"); System.out.println("****歡迎進(jìn)入系統(tǒng)****"); System.out.println("登錄請(qǐng)按1,注冊(cè)請(qǐng)按2"); Scanner input=new Scanner(System.in); int a=input.nextInt(); if(a==1) { System.out.println("請(qǐng)輸入賬號(hào):"); String b=input.next(); System.out.println("請(qǐng)輸入密碼:"); String c=input.next(); for (member mm: t1.gaMembers) { if(mm.phone.equals(b) && mm.pass.equals(c)) { System.out.println("登錄成功!請(qǐng)進(jìn)入游戲"); int num1=(int)(Math.random()*100); int n1=num1/10; int n2=num1%10; int num2=(int)(Math.random()*100); int n3=num2/10; int n4=num2%10; int num=num1*100+num2; System.out.println("請(qǐng)隨機(jī)輸入四個(gè)數(shù):"); int x1=input.nextInt(); int x2=x1/1000; int x3=(x1/100)%10; int x4=(x1/10)%100; int x5=x1%1000; System.out.println("中獎(jiǎng)數(shù)字為:"+num); if (x1==num) { System.out.println("恭喜獲得一等獎(jiǎng)!"); } else if (n1==x2 &&n2==x2 && n3==x3) { System.out.println("恭喜獲得二等獎(jiǎng)!"); } else if (n1==x2 &&n2==x2) { System.out.println("恭喜獲得三等獎(jiǎng)!"); } else { System.out.println("不中獎(jiǎng)!"); } } else { System.out.println("賬號(hào)或密碼錯(cuò)誤!請(qǐng)重新輸入"); } } } else { System.out.println("請(qǐng)輸入注冊(cè)賬號(hào):"); String d=input.next(); System.out.println("請(qǐng)輸入注冊(cè)密碼:"); String e=input.next(); member m3=new member(d, e); gaMembers.add(m3); for(member mm:gaMembers) { p1.members.add(m3); } System.out.println("你的會(huì)員信息為:"); t1.foreachset(p1); System.out.println("注冊(cè)成功!請(qǐng)重新登錄"); } }? ? public void foreachset(people p1)? ? {? ? for(member cc:p1.members)? ? {? ? System.out.println(cc.phone+","+cc.pass);? ? }? ? }? ??? ??}/** ?1. ? ??System.out.println("賬號(hào)或密碼錯(cuò)誤!請(qǐng)重新輸入");這一句代碼總是重復(fù)執(zhí)行。? ?2. ? 進(jìn)入注冊(cè),注冊(cè)成功后該怎樣重新返回到登錄時(shí)賬號(hào)密碼的輸入界面?難道要把那段登錄的代碼復(fù)制到注冊(cè)成功后面而不能用循環(huán)或者什么重新返回到那個(gè)位置上嗎?
1 回答
已采納

慕粉4075985
TA貢獻(xiàn)104條經(jīng)驗(yàn) 獲得超33個(gè)贊
前言:貼代碼要貼得規(guī)范,貼重點(diǎn),貼得亂七八糟有耐心的人才給你看
1,你把它寫(xiě)到了循環(huán)內(nèi)導(dǎo)致重復(fù)執(zhí)行
2、while(true)
添加回答
舉報(bào)
0/150
提交
取消