EJERCICIO DO WHILE

Un programa que solicite por teclado 2 numeros enteros, hacer el promedio, suma, resta, multiplicacion.

/*
 * 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 otro;
import java.util.Scanner;

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

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
     Scanner teclado = new Scanner(System.in);
     int suma,cantidad,valor,promedio, resta;
   
     suma=0;
     cantidad=0;
     resta=0;
   
     do {
     System.out.println("Ingrese el valor:");
     valor=teclado.nextInt();
     if (valor!=0){
         suma=suma+valor;
         resta=resta-valor;
         cantidad++;
     }
   
   
     }
   
     while (valor!=0);
     if (cantidad!=0){
     promedio=(suma/cantidad);
     resta=promedio-valor;
   
 
     System.out.println("el promedio es "+promedio);
   
     System.out.println("la suma  es "+suma);
     System.out.println("la resta  es "+resta);
   

     }
     else {
     System.out.println("No dio mas valores");}
   
   
   
}
}

Share this

Related Posts

Previous
Next Post »