Java_Proyectos_NetBeans/Apuntes_guia/basicos/SwitchDoWhileForRandom.java

48 lines
1.6 KiB
Java
Raw Normal View History

2020-11-16 01:57:01 -03:00
//--------------- jp.av.dev@gmail.com ---------------//
/* Switch Case, Scanner, Random, For, While, Do While*/
package apuntes.pkg;
import java.util.Random;
import java.util.Scanner;
public class SwitchDoWhileFor {
public static void main(String[] args) {
int notas[]= new int[20];
Random r = new Random();
Scanner s = new Scanner(System.in);
System.out.println("");
int opc = 0;
do{
System.out.println("0 Salir\n1 Llenar arreglo\n2 Imprimir");
opc = s.nextInt();
switch(opc){
case 0:
System.out.println("Opcion 0");
break;
case 1:
for (int i = 0; i < 20; i++) {
int numero = (int) (Math.random() * 70) + 20;
notas[i] = numero;}
break;
case 2:
for (int i = 0; i < 20; i++) {
System.out.print(notas[i] + ", ");
}
System.out.println("\n");
break;
case 3:
float suma = 0,promedio = 0; //FLOAT asignacion Numero REAL
for (int i = 0; i < 200; i++) {
suma = suma + notas[i];
}
promedio = suma/20;
System.out.println("El promedio es " + promedio);
break;
}
}while(opc!=0);
} //END MAIN
} //END CLASS