Skip to content

[DESEMPENHO] Troco,java - Loop infinito #8

@matulevicius123

Description

@matulevicius123

protected PapelMoeda[] papeisMoeda;
public Troco(int valor) {
papeisMoeda = new PapelMoeda[6];
int count = 0;
while (valor % 100 != 0) {
count++;
}
papeisMoeda[5] = new PapelMoeda(100, count);
count = 0;
while (valor % 50 != 0) {
count++;
}
papeisMoeda[4] = new PapelMoeda(50, count);
count = 0;
while (valor % 20 != 0) {
count++;
}
papeisMoeda[3] = new PapelMoeda(20, count);
count = 0;
while (valor % 10 != 0) {
count++;
}
papeisMoeda[2] = new PapelMoeda(10, count);
count = 0;
while (valor % 5 != 0) {
count++;
}
papeisMoeda[1] = new PapelMoeda(5, count);
count = 0;
while (valor % 2 != 0) {
count++;
}
papeisMoeda[1] = new PapelMoeda(2, count);
}

Por nunca atualizar o valor de 'valor', todos os whiles resultam em loops infinitos.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DesempenhoAlgumas rotinas executam comandos ou laços (loops) desnecessários

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions