Array padded [closed]

0

I am learning the Arrays, and a problem has arisen, is to fill in an array of integers by keyboard and add the total of those numbers. The truth is that I have been looking for information but I can not find exactly how to do that operation, if someone has a link to a forum I can tell you how it is done I would appreciate it.

I add what I was wearing code:

package boletinArrays;
import static boletinExpresiones.Teclado.*;
public class EjerciciosArrays {
public static void main(String[] args) {
    ej01();

}

/*
 * 1.- Pedir datos al usuario
 *  1.1.- Pedir tamaño del array
 *  1.2.- Pedir tantos numeros de enteros como el tamaño
 * 2.- Suma todos los arrays
 * 3.- Devolver resultados
 */
public static int ej01() {
    int sum = 0,p;
    String x;
    String s,n;
    x=readString("Dame un numero: ");
    int num[]=new int[Integer.parseInt(x)];
        System.out.println(num);

    //1.- Pedir datos al usuario
    //1.1.- Pedir tamaño del array
    return sum;

readString is a class where I have all keyboard uses controlled

    
asked by Victor Yil 04.01.2019 в 19:45
source

1 answer

3

Let's see I've told you all the code of how I would do it, if you do not understand something, you tell me!

package ex02;

import java.util.Scanner;

public class Ex {

	public static void main(String[] args) {
		Scanner lec = new Scanner(System.in);
		int arraySize; //Variable para el tamaño de la array
		int sumaTotal=0;
		
		/*
		 * 1.- Pedir datos al usuario
		 *  1.1.- Pedir tamaño del array
		 *  1.2.- Pedir tantos numeros de enteros como el tamaño
		 * 2.- Suma todos los arrays
		 * 3.- Devolver resultados
		 */
		System.out.println("Start"); //Arranca el programa
		
		System.out.println("Introduce el tamaño de la array:");
		arraySize=lec.nextInt(); // Guardamos el tamaño de la array
		
		int array[]= new int[arraySize]; //Definimos la array con la variable del tamaño
		
		System.out.println("Procedemos a rellenar la array");
		for (int i = 0; i < array.length; i++) {
			array[i]=lec.nextInt();  //Guardamos cada valor en su posicion
			sumaTotal+=array[i];  //Sumamos todos los valores
			
		}
		
		
		System.out.println("Suma:"+ sumaTotal); // Printamos tamaño total
		

	}
    
answered by 07.01.2019 / 19:12
source