Created
August 26, 2013 15:56
-
-
Save ninetails/6343067 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.Scanner; | |
public class ExercicioUm | |
{ | |
public static void main(String args[]) | |
{ | |
Scanner input = new Scanner(System.in); | |
int in, max; | |
System.out.println("Digite 3 números inteiros:"); | |
max = input.nextInt(); | |
in = input.nextInt(); | |
if (in >= max) { | |
max = in; | |
} | |
in = input.nextInt(); | |
if (in >= max) { | |
max = in; | |
} | |
System.out.printf("\nO maior número é: %d\n", max); | |
} | |
} |
This file contains hidden or 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.Scanner; | |
public class ExercicioTres | |
{ | |
public static void main(String args[]) | |
{ | |
Scanner input = new Scanner(System.in); | |
int dia, mes, ano; | |
System.out.print("Digite o dia: "); | |
dia = input.nextInt(); | |
System.out.print("Digite o mês: "); | |
mes = input.nextInt(); | |
System.out.print("Digite o ano: "); | |
ano = input.nextInt(); | |
if (dia < 1) { | |
System.out.printf("\nA data %d/%d/%d é inválida\n", dia, mes, ano); | |
} else { | |
switch (mes) { | |
case 1: | |
case 3: | |
case 5: | |
case 7: | |
case 8: | |
case 10: | |
case 12: | |
if (dia <= 31) { | |
System.out.printf("\nA data %d/%d/%d é válida\n", dia, mes, ano); | |
} else { | |
System.out.printf("\nA data %d/%d/%d é inválida\n", dia, mes, ano); | |
} | |
break; | |
case 4: | |
case 6: | |
case 9: | |
case 11: | |
if (dia <= 30) { | |
System.out.printf("\nA data %d/%d/%d é válida\n", dia, mes, ano); | |
} else { | |
System.out.printf("\nA data %d/%d/%d é inválida\n", dia, mes, ano); | |
} | |
break; | |
case 2: | |
if (ano % 4 == 0 && ano % 100 != 0 && dia <= 29) { | |
System.out.printf("\nA data %d/%d/%d é válida\n", dia, mes, ano); | |
} else { | |
if (dia <= 28) { | |
System.out.printf("\nA data %d/%d/%d é válida\n", dia, mes, ano); | |
} else { | |
System.out.printf("\nA data %d/%d/%d é inválida\n", dia, mes, ano); | |
} | |
} | |
break; | |
default: | |
System.out.printf("\nA data %d/%d/%d é inválida\n", dia, mes, ano); | |
} | |
} | |
} | |
} |
This file contains hidden or 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.Scanner; | |
public class ExercicioUm | |
{ | |
public static void main(String args[]) | |
{ | |
Scanner input = new Scanner(System.in); | |
int in, menor, meio, maior; | |
System.out.println("Digite 3 números inteiros:"); | |
menor = input.nextInt(); | |
in = input.nextInt(); | |
if (in > menor) { | |
meio = in; | |
} else { | |
meio = menor; | |
menor = in; | |
} | |
in = input.nextInt(); | |
if (in > meio) { | |
maior = in; | |
} else { | |
maior = meio; | |
if (in > menor) { | |
meio = in; | |
} else { | |
meio = menor; | |
menor = in; | |
} | |
} | |
System.out.printf("\nOs três números, em ordem crescente, são: %d, %d e %d\n", menor, meio, maior); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment