Created
April 3, 2024 21:38
-
-
Save leofernandesmo/c9dff8edd27be4a3042f87e4c5d0d303 to your computer and use it in GitHub Desktop.
Depure o código abaixo, localize o erro e faça as correções
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
import java.util.Map; | |
import java.util.Scanner; | |
public class ControleEstoque { | |
private static Map<String, Integer> estoque = new HashMap<>(); | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
while (true) { | |
System.out.println("Escolha uma opção:"); | |
System.out.println("1 - Adicionar Produto"); | |
System.out.println("2 - Vender Produto"); | |
System.out.println("3 - Exibir Estoque"); | |
System.out.println("4 - Sair"); | |
int opcao = scanner.nextInt(); | |
switch (opcao) { | |
case 1: | |
adicionarProduto(scanner); | |
break; | |
case 2: | |
venderProduto(scanner); | |
break; | |
case 3: | |
exibirEstoque(); | |
break; | |
case 4: | |
System.out.println("Saindo do programa..."); | |
return; | |
default: | |
System.out.println("Opção inválida!"); | |
} | |
} | |
} | |
private static void adicionarProduto(Scanner scanner) { | |
System.out.println("Digite o nome do produto:"); | |
String nome = scanner.next(); | |
System.out.println("Digite a quantidade do produto:"); | |
int quantidade = scanner.nextInt(); | |
if (estoque.containsKey(nome)) { | |
quantidade += estoque.get(nome); | |
} | |
estoque.put(nome, quantidade); | |
System.out.println("Produto adicionado com sucesso!"); | |
} | |
private static void venderProduto(Scanner scanner) { | |
System.out.println("Digite o nome do produto:"); | |
String nome = scanner.next(); | |
System.out.println("Digite a quantidade a ser vendida:"); | |
int quantidade = scanner.nextInt(); | |
if (estoque.containsKey(nome)) { | |
int estoqueAtual = estoque.get(nome); | |
if (estoqueAtual >= quantidade) { | |
estoque.put(nome, estoqueAtual - quantidade); | |
System.out.println("Venda realizada com sucesso!"); | |
} else { | |
System.out.println("Quantidade insuficiente em estoque!"); | |
} | |
} else { | |
System.out.println("Produto não encontrado em estoque!"); | |
} | |
} | |
private static void exibirEstoque() { | |
System.out.println("Estoque atual:"); | |
for (String produto : estoque.keySet()) { | |
int quantidade = estoque.get(produto); | |
System.out.println(produto + ": " + quantidade); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
public class ListaDeCompras { | |
public static void main(String[] args) { | |
ListaDeCompras lista = new ListaDeCompras(); | |
lista.adicionarItem("Maçã"); | |
lista.adicionarItem("Banana"); | |
lista.adicionarItem("Pêra"); | |
lista.removerItem("Banana"); | |
lista.removerItem("Laranja"); | |
lista.exibirLista(); | |
} | |
private ArrayList<String> itens; | |
public ListaDeCompras() { | |
this.itens = new ArrayList<>(); | |
} | |
public void adicionarItem(String item) { | |
itens.add(item); | |
} | |
public void removerItem(String item) { | |
itens.remove(item); | |
} | |
public void exibirLista() { | |
System.out.println("Lista de Compras:"); | |
for (String item : itens) { | |
System.out.println("- " + item); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
/* | |
Este programa implementa um algoritmo para encontrar o menor número primo maior que um número inteiro fornecido pelo usuário. | |
*/ | |
// Função para verificar se um número é primo | |
int verificar_primo(int num) { | |
if (num <= 1) | |
return 0; // Não é primo | |
for (int i = 2; i * i <= num; i++) { | |
if (num % i == 0) | |
return 0; // Não é primo | |
} | |
return 1; // É primo | |
} | |
// Função para encontrar o próximo número primo após um número dado | |
int proximo_primo(int num) { | |
num++; | |
while (!verificar_primo(num)) | |
num++; | |
return num; | |
} | |
int main() { | |
int n; | |
printf("Digite um numero inteiro: "); | |
scanf("%d", &n); | |
int primo = proximo_primo(n); | |
printf("O menor numero primo maior que %d eh: %d\n", n, primo); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment