1
I’m creating a 'fake bank' and wanted to make a method in which partially shows the password.
I created an array called senha2 and the first 4 characters are shown as *, for example:
senha : ****restoDaSenha
But if I do:
String senha3 = senha.charAt(4);
String[] senha2 = { "*", "*", "*", "*", this.senha3};
It does not give error but it happens in the output:
Password : [Ljava.lang.String;@15db9742
What’s the problem in the existing code? It’s an implementation problem, language application?
My code:
package bancofake;
import javax.swing.JOptionPane;
public class Banco {
    String nome; // Dono -> fisico ou juridico
    String senha; // Senha -> Senha da conta para nenhum ladrão louco roubar dinheiro
    double saldo;
    int id; // Id da conta
    String[] senha2 = { "*", "*", "*", "*"};
    int tentativa;
      public void criarSenha() {
          String senhacriada = (JOptionPane.showInputDialog("Qual a senha ?"));
            if(senhacriada.length() >= 8) { 
                System.out.println("Senha criada");
                this.senha = senhacriada;
            }else{
                System.err.println("A senha deve ter no minimo 8 caracteres !"); 
                if(tentativa < 2) {
                    this.tentativa += 1;
                    this.criarSenha();
                }
            }
      }
    public void depositar(double quantidade) {
        int idrecebeu = Integer.parseInt(JOptionPane.showInputDialog("Qual o ID da conta ?"));
        if (idrecebeu == this.id) {
            if (quantidade >= 0) {
                this.saldo += quantidade;
                System.out.println("Depositado R$" + quantidade + " com Sucesso !");
                System.out.println("==| Informação |==");
                System.out.println("Id da Conta : " + this.id);
                System.out.println("Nome do Dono(fisico ou juridico) : ");
                System.out.println(this.nome);
                System.out.println("Saldo : R$" + this.saldo);
            } else if (quantidade <= 0) {
                System.out.println("Você não pode depositar R$" + quantidade + " !");
                System.out.println("Pois a quantidade é igual ou menor que 0 !");
            } else {
                System.err.println("A quantidade não é Depositavel !");
            }
        } else {
            System.out.println("O ID está incorreto e/ou não existe !");
        }
    }
    public void retirar(double quantidade) {
        int idrecebido = Integer.parseInt(JOptionPane.showInputDialog("Qual o ID da conta ?"));
        String senharecebida = (JOptionPane.showInputDialog("Qual a senha ?"));
        if (idrecebido == this.id && senharecebida == this.senha) {
            if (saldo != 0) {
                if (quantidade >= 0) {
                    this.saldo -= quantidade;
                    System.out.println("Retirado R$" + quantidade + " com Sucesso !");
                    System.out.println("==| Informação |==");
                    System.out.println("Id da Conta : " + this.id);
                    System.out.println("Nome do Dono(fisico ou juridico) : ");
                    System.out.println(this.nome);
                    System.out.println("Saldo : R$" + this.saldo);
                } else if (quantidade <= 0) {
                    System.out.println("Você não pode retirar R$" + quantidade + " !");
                    System.out.println("Pois a quantidade é igual ou menor que 0 !");
                } else {
                    System.err.println("A quantidade não é Retiravel !");
                }
            } else if (saldo <= 0) {
                System.out.println("A quantidade não é permitida !");
                System.out.println("Saldo : " + this.saldo);
            }
        } else {
            System.out.println("O ID ou a Senha está Incorreto !");
        }
    }
    public void verificarSaldo() {
        System.out.println("Saldo : " + this.saldo);
        System.out.println("Id da conta : " + this.id);
        System.out.println("Dono da conta : " + this.nome);
        System.out.println("Senha : " + this.senha);
    }
    public void verificarsenha() {
        System.out.println("Senha : "+this.senha);
    }
    public static void main(String[] args) {
    }
}
For example, if the password is "abcdefgh", I want the output to be:
****efgh
						
Edit the question and include all the code involved, only that you posted only to say that you are printing the variable memory address
– rnd_rss
The code I put everything , It’s kind of bad because I’m learning Java this month .
– Vitor Henrique05
Like you’re printing on the screen?
– Leonardo Teruel
System.out.prinln("Senha : "+senha_parcialmente);– Vitor Henrique05
if password = "12345678" then Password partially = "5678" or "1234"
– Vitor Henrique05