SHARE
TWEET

Clase while, do while, switch

a guest Aug 19th, 2019 82 in 3 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package javaapplication1;   //No copiar
  7. import java.util.Scanner;   //Copiar
  8.  
  9. /**
  10.  *
  11.  * @author 17131711-8
  12.  */
  13. public class JavaApplication1 { //No copiar
  14.  
  15.     /**
  16.      * @param args the command line arguments
  17.      */
  18.     public static void main(String[] args) {    //Copiar el contenido
  19.         // TODO code application logic here
  20.         int i = 0;
  21.         int option = 0;
  22.         Scanner sc = new Scanner(System.in);
  23.         //Caso while
  24.         while (i < 10){
  25.             System.out.println("Número: " + i);  
  26.             i++;
  27.         }
  28.         i = 0;
  29.         //Caso do while
  30.         do{
  31.             System.out.println("Número: " + i);
  32.             i++;
  33.         }  while (i <= 10);
  34.         System.out.println("Ingresa un número entre 1 y 2: ");
  35.         option = sc.nextInt();
  36.         //Caso switch
  37.         switch (option){
  38.             case 1:
  39.                 System.out.println("Escogiste opcion 1");
  40.                 break;
  41.             case 2:
  42.                 System.out.println("Escogiste opcion 2");
  43.                 break;
  44.             default:
  45.                 System.out.println("Escogiste cualquier otra opción");
  46.                 break;
  47.         }
  48.     }
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top