-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathDuasNotas.java
More file actions
38 lines (33 loc) · 1.42 KB
/
Copy pathDuasNotas.java
File metadata and controls
38 lines (33 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Gilberto é um famoso vendedor de esfirras na região. Porém, apesar de todos gostarem de suas esfirras, ele só sabe dar o troco com duas notas, ou seja, nem sempre é possível receber o troco certo. Para facilitar a vida de Gil, escreva um programa para ele que determine se é possível ou não devolver o troco exato utilizando duas notas.
// As notas disponíveis são: 2, 5, 10, 20, 50 e 100.
// Entrada
// A entrada deve conter o valor inteiro N da compra realizada pelo cliente e, em seguida, o valor inteiro M pago pelo cliente (N < M ≤ 104). A entrada termina com N = M = 0.
// Saída
// Seu programa deverá imprimir "possible" se for possível devolver o troco exato ou "impossible" se não for possível.
import java.io.IOException;
import java.util.Scanner;
public class DuasNotas {
public static void main(String[] args) throws IOException {
Scanner leitor = new Scanner(System.in);
while (true) {
int N = leitor.nextInt();
int M = leitor.nextInt();
int troco = M - N;
int[] notas = { 2, 5, 10, 20, 50, 100 };
boolean possivel = false;
if (N == 0 && M == 0)
break;
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
if (notas[i] + notas[j] == troco)
possivel = true;
}
}
if (possivel == true)
System.out.println("possible");
else {
System.out.println("impossible");
}
}
}
}