Created
October 30, 2012 18:38
-
-
Save marioplumbarius/3982142 to your computer and use it in GitHub Desktop.
Exemplo da utilização do Switch em Java
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
/* só pode ser utilizada com os seguintes tipos: | |
* byte, short, char, int e String. | |
* Ótima opção para fazer Menus. | |
*/ | |
package condicional; | |
import java.util.Scanner; | |
public class Switch { | |
public static void main(String[] args){ | |
Scanner entrada = new Scanner(System.in); | |
int teste; | |
//criacao da variavel teste | |
System.out.println("Digite o mês em número inteiro"); | |
teste = entrada.nextInt(); | |
//entrada de dados | |
switch(teste){ | |
case 1: | |
System.out.println("Janeiro"); | |
break; | |
case 2: | |
System.out.println("Fevereiro"); | |
break; | |
case 3: | |
System.out.println("Março"); | |
break; | |
case 4: | |
System.out.println("Abril"); | |
break; | |
default: | |
System.out.println("Digite SOMENTE números entre 1 e 4"); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment