标题:大家帮忙看看从键盘输入那该怎么改
只看楼主
lowryfly
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2012-11-28
结帖率:75%
 问题点数:0 回复次数:1 
大家帮忙看看从键盘输入那该怎么改
package lang.lang1;
import *;

import

class person{
    private int No;
    String Name,password;
    private float yue;
    void initperson(String newName,String newpassword,int newNo,float newyue){
        Name = newName;
        password = newpassword;
        yue = newyue;
        No = newNo;
    }
    void printperson(){
        System.out.println("户名:"+Name);
        System.out.println("账号:"+No);
        System.out.println("余额:"+yue);
    }
    void examinperson() throws IOException {
        System.out.println("请输入密码");
        BufferedReader str = new BufferedReader(new InputStreamReader(System.in));
        String a = str.readLine();
         System.out.println(a);
        if(a==password){
            printperson();
        }
        else{
            System.out.println("密码错误");
        }
    }
}
public class Bank {

    public static void main(String[] args) throws IOException {
        person wo = new person();
        wo.initperson("张三", "abc", 123456, 5000);
        wo.examinperson();

    }

}
就是简单的输入密码显示信息,输入部分搞不明白
搜索更多相关主题的帖子: package import password person private 
2013-06-06 19:37
Kingbox_tang
Rank: 7Rank: 7Rank: 7
来 自:天津师范大学
等 级:黑侠
威 望:3
帖 子:146
专家分:677
注 册:2012-11-27
得分:0 
同学这样就可以啦。
class person{
    private int No;
    String Name,password;
    private float yue;
    void initperson(String newName,String newpassword,int newNo,float newyue){
        Name = newName;
        password = newpassword;
        yue = newyue;
        No = newNo;
    }
    void printperson(){
        System.out.println("户名:"+Name);
        System.out.println("账号:"+No);
        System.out.println("余额:"+yue);
    }
    void examinperson() throws IOException {
        System.out.println("请输入密码");
     //   BufferedReader str = new BufferedReader(new InputStreamReader(System.in));
        Scanner str=new Scanner(System.in);
        String a = str.next();
         System.out.println(a);
        if(a.equals(password)){
            printperson();
        }
        else{
            System.out.println("密码错误");
        }
    }
}
public class Bank{

    public static void main(String[] args) throws IOException {
        person wo = new person();
        wo.initperson("张三", "abc", 123456, 5000);
        wo.examinperson();

    }

}
输出结果:请输入密码
abc
abc
户名:张三
账号:123456
余额:5000.0

旨在提高编程水平,学有所用,学有所成,学有所为。
2013-06-06 20:46



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




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

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