Baixe o app para aproveitar ainda mais
Prévia do material em texto
Estes exercícios são de alunos para alunos, Tente resolver primeiro para depois comparar as respostas, pois você não irá aprender se fizerem por você! ^^ Exercícios de Lógica II 1. Entre com quatro notas de um aluno e verificar se a nota é maior ou igual a 7 se sim mostrar mensagem "Aluno Aprovado", senão mostrar mensagem "Aluno em exame", receber nota de exame do aluno e verificar se nota de exame é maior ou igual a 5 , se sim mostrar mensagem "Aluno Aprovado em Exame", senão mostrar mensagem "Aluno Reprovado em Exame". 2. Entrar com dois nomes e verificar se os dois são iguais, se sim mostrar mensagem "Nomes Iguais", senão mostrar mensagem "Nomes Diferentes" 3. Ler um valor e escrever se é positivo ou negativo (considere o valor zero como positivo). 4. Ler dois valores (considere que não serão lidos valores iguais) e escrever o maior deles. 5. Ler dois valores (considere que não serão lidos valores iguais) e escrevê-los em ordem crescente. 6. Escreva um algoritmo para ler um valor (do teclado) e escrever (na tela) o seu antecessor. 7. Ler o nome de 2 times e o número de gols marcados na partida (para cada time). Escrever o nome do vencedor. Caso não haja vencedor deverá ser impressa a palavra EMPATE. Respostas Exercício 01 import java.util.Scanner; public class Ex01 { public static void main(String args[]) { Scanner input = new Scanner(System.in); double nota; double somaNotas = 0; double media; double notaExame; for ( int i = 1; i <= 4; i++) { System.out.print("Digite a "+i+"ª nota: "); nota = input.nextDouble(); somaNotas = somaNotas + nota; } media = somaNotas / 4; if ( media >= 7 ) { System.out.printf("Aluno aprovado. Media %s. ", media); } else { System.out.printf("Aluno em exame. Media %s .\n", media); System.out.print("Digite a nota do exame: "); notaExame = input.nextDouble(); if ( notaExame >= 5 ) { System.out.printf("Aluno aprovado em exame"); } else { System.out.printf("Aluno reprovado em exame"); } } } } Exercício 02 import java.util.Scanner; public class Ex02 { public static void main(String args[]) { Scanner input = new Scanner(System.in); String nome1; String nome2; System.out.print("Digite o primeiro nome: "); nome1 = input.nextLine(); System.out.print("Digite o segundo nome: "); nome2 = input.nextLine(); if ( nome1.equals(nome2) ) { System.out.printf("Nomes iguais"); } else { System.out.printf("Nomes Diferentes"); } } } Exercício 03 import java.util.Scanner; public class Ex03 { public static void main(String args[]) { Scanner input = new Scanner(System.in); int num; System.out.print("Insira um valor: "); num = input.nextInt(); if ( num >= 0 ) { System.out.printf("O valor é positivo"); } else { System.out.printf("O valor é negativo"); } } } Exercício 04 import java.util.Scanner; public class Ex04 { public static void main(String args[]) { Scanner input = new Scanner(System.in); int x, y; System.out.print("Insira o primeiro valor: "); x = input.nextInt(); System.out.print("Insira o segundo valor: "); y = input.nextInt(); if ( x > y ) { System.out.printf("O maior é %s .",x); } else { System.out.printf("O maior é %s .",y); } } } Exercício 05 import java.util.Scanner; public class Ex05 { public static void main(String args[]) { Scanner input = new Scanner(System.in); int x,y; System.out.print("Insira o primeiro valor: "); x = input.nextInt(); System.out.print("Insira o segundo valor: "); y = input.nextInt(); if ( x > y ) { System.out.printf(" %s ... %s ", y , x); } else { System.out.printf(" %s ... %s ", x, y ); } } } Exercício 06 import java.util.Scanner; public class Ex06 { public static void main(String args[]) { Scanner input = new Scanner(System.in); int num; System.out.print("Insira um valor: "); num = input.nextInt(); System.out.printf(" Antecessor de %s = %s ", num ,( num - 1 )); } } Exercício 07 import java.util.Scanner; public class Ex07 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String nome1 = new String(); // nome do time 1 String nome2 = new String(); //nome do time 2 int time1; // gols do time 1 int time2; // gols do time2 System.out.print("Insira o numero do time 1: "); nome1 = input.next(); System.out.print("Insira o numero de gols do Time 1: "); time1 = input.nextInt(); System.out.print("Insira o nome do time 2: "); nome2 = input.next(); System.out.print("Insira o numero de gols do Time 2: "); time2 = input.nextInt(); if ( time1 > time2 ) { System.out.printf("O vencedor é o time %s ", nome1); } if ( time1 == time2 ) { System.out.printf("EMPATE"); } } }
Compartilhar