标题:怎么让我的输入账号与用户名成为同一个变量
只看楼主
W18483638147
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2016-5-9
结帖率:0
 问题点数:0 回复次数:2 
怎么让我的输入账号与用户名成为同一个变量
package test;

public class Admin {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Register register = new Register();
        register.show();
        
        Login login = new Login();
        login.show();
        
    }   

}
package test;
import java.util.Scanner;

public class Register {

        String uname;
        String pwd;
        
        public void show()
        {   
            Scanner input = new Scanner(System.in);
            System.out.print("请注册用户名:");
            this.uname = input.next();
            System.out.print("请输入密码:");
            this.pwd = input.next();
            if (this.pwd.length() >= 6)
            {
            System.out.print("注册成功!");
            }   
            else
            {
            System.out.print("用户名不能少于6位!");
            }
        }

        public String getUname() {
            return uname;
        }

        public void setUname(String uname) {
            this.uname = uname;
        }

        public String getPwd() {
            return pwd;
        }

        public void setPwd(String pwd) {
            this.pwd = pwd;
        }


}
package test;

import java.util.Scanner;

public class Login {
        String uname;
        String pwd;
        
        public void show(){
        Scanner input = new Scanner(System.in);
        System.out.print("请输入用户名:");
        uname = input.next();
        System.out.print("请输入密码:");
        pwd = input.next();
        if (uname.equals("TOM")&& pwd.equals("1234567"))
            {
            System.out.print("登录成功!");
                }
            else
            {
                System.out.print("用户名或密码不匹配,登录失败!");
            }
        }

        public String getUname() {
            return uname;
        }

        public void setUname(String uname) {
            this.uname = uname;
        }

        public String getPwd() {
            return pwd;
        }

        public void setPwd(String pwd) {
            this.pwd = pwd;
        }
    }


搜索更多相关主题的帖子: register package 用户名 public import 
2016-05-20 13:37
dkplus
Rank: 2
等 级:论坛游民
帖 子:12
专家分:45
注 册:2016-5-17
得分:0 
帮你顶下帖,让大神看到你

linux教程,微信公众号dkplus
2016-05-22 18:28
current
Rank: 1
等 级:新手上路
威 望:1
帖 子:15
专家分:5
注 册:2016-5-31
得分:0 
定义一个全局的变量阿
2016-05-31 10:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-465050-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025893 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved