Skip to content

Instantly share code, notes, and snippets.

@marioluan
Created October 30, 2012 18:38
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marioluan/3982142 to your computer and use it in GitHub Desktop.
Save marioluan/3982142 to your computer and use it in GitHub Desktop.
Exemplo da utilização do Switch em Java
/* 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