Estructura repetitiva DO WHILE

Esta estructura ejecuta al menos una vez el bloque repetitivo a diferencia del while o del for, esta estructura repetitiva se utiliza cuando conocemos de antemano que una vez se ejecutara el bloque
la condición de la estructura esta abajo del bloque a repetir a diferencia del while o del for que están en la parte superior



EJERCICIO PRACTICO

escriba un programa que solicite un numero entero entre 0 y 999, 
y nos muestre un mensaje de cuantos digitos tiene el mismo, 
el programa termina cuando ingrese 0.


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package programa;
import java.util.Scanner;

/**
 *
 * @author 305
 */
public class Programa {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here

            Scanner teclado = new Scanner(System.in);
            int valor;
            do {
            System.out.println("Ingrese el valor entre 0 y 99999:");
            valor=teclado.nextInt();
            if (valor>1000 && valor<=99999) {
                System.out.println("tiene 5 digitos");
            } 
            
            if (valor>1000 && valor<=9999) {
                System.out.println("tiene 4 digitos");
            } 
            
            if (valor>100 && valor<=999) {
                System.out.println("tiene 3 digitos");
            } 
            
            if (valor>10 && valor<=99) {
                System.out.println("tiene 2 digitos");
            } 
            
             if (valor <= 9) {
                System.out.println("tiene 1 digitos");
            } 
            
            
            
               
            }
      
             while(valor!=0);
          
          
 }  
}



Share this

Related Posts

Previous
Next Post »