-1
This code I’m writing, where the option 1 the user enters notes that he wishes to insert into an ATM where it was to stop when the note 1 was inserted.
In the option 2 is to enter the value of the serve and this serve will only use the notes that were inserted.
In the option 0 the program ends.
Any way I can inject this condition of footnote 1 close loop?
public static void main(String[] args) {
// TODO Auto-generated method stub
String menu = "* MENU OPÇÕES * " + "\n" + "1 - Notas Existentes" + "\n" + "2 - Saque" + "\n" + "0 - Sair" + "\n";
int [] possiveis = new int [7];
int work = 1;
int div1=0,div2=0,div3 = 0,div4 = 0,div5 = 0,div6 = 0,div7 = 0;
int resto1=0,resto2=0,resto3 = 0,resto4 = 0,resto5 = 0,resto6 = 0,resto7 = 0;
while (work!=0) {
System.out.println(menu);
Scanner entrada = new Scanner (System.in);
System.out.println("Digite a opçao desejada: ");
int opcao = entrada.nextInt();
if (opcao==1) {
for (int i=0;i<possiveis.length;i++) {
System.out.println("Digite as notas disponiveis");
possiveis[i] = entrada.nextInt();
}
for (int i =0; i<possiveis.length;i++) {
if(possiveis[i]!=1) {
System.out.println(possiveis[i]);
}else if (possiveis[i]==1 ){
System.out.println(possiveis[i]);
}
work=1;
}
}else if (opcao==2) {
System.out.println("Digite o valor do saque");
int saque = entrada.nextInt();
if ((possiveis[0]>0)|| (possiveis[1] >0) || (possiveis[2] >0) || (possiveis[3] >0) ||(possiveis[4]>0) || (possiveis[5]>0) || (possiveis[6]>0)){
div1 = saque / possiveis[0];
resto1 = saque % possiveis[0];
if (resto1>0){
div2 = resto1 / possiveis[1];
resto2 = resto1 % possiveis[1];}
if (resto2>0){
div3 = resto2 / possiveis[2];
resto3 = resto2 % possiveis[2];}
if (resto3>0){
div4 = resto3 / possiveis[3];
resto4 = resto3 % possiveis[3];}
if (resto4>0){
div5 = resto4 / possiveis[4];
resto5 = resto4 % possiveis[4];}
if ( resto5>0){
div6 = resto5 / possiveis [5];
resto6 = resto5 % possiveis [5];}
if (resto6>0){
div7 = resto6 / possiveis [6];
resto7 = resto6 % possiveis [6];}
}
if (div1!=0) {
System.out.println("Total de notas de " + possiveis[0] + " = " + div1);
}
if (div2!=0) {
System.out.println("Total de notas de " + possiveis[1] + " = " + div2);
}
if (div3!=0) {
System.out.println("Total de notas de " + possiveis[2] + " = " + div3);
}
if (div4!=0) {
System.out.println("Total de notas de " + possiveis[3] + " = " + div4);
}
if (div5!=0) {
System.out.println("Total de notas de " + possiveis[4] + " = " + div5);
}
if (div6!=0) {
System.out.println("Total denotas de " + possiveis[5] + " = " + div6);
}
if (div7!=0) {
System.out.println("Total de notas de " + possiveis[6] + " = " + div7);
}
work=1;
}else if (opcao==0) {
work=0;
}else {
System.out.println("Opcão invalida");
}
}
}
Using a
break
?– Jéf Bueno
But in case it was to stop typing the notes after typing 1,using break will only solve the issue of printing notes
– Ian Fonteles
You want to interrupt the first
for
(what you havepossiveis[i] = entrada.nextInt()
)? If that’s it, you can put thebreak
within thefor
, that only thefor
is interrupted and thewhile
keeps rolling. Another thing, in the secondfor
vc faz: if the value is different from 1, prints, and if it is equal to 1, also prints, what is the purpose of that?– hkotsubo
Really that second for was logical mistake my haha, thank you for the touch
– Ian Fonteles