Problema en un ejercicio de arreglos
Publicado por Carlos (1 intervención) el 19/05/2017 17:51:42
Estoy haciendo un ejercicio y tengo problemas en esta parte:
realizar un programa que elimine las secuencias de tamaño N. Para
eliminar tenga en cuenta hacer los corrimientos correspondientes y completar con ceros
al final.
Mi codigo:
realizar un programa que elimine las secuencias de tamaño N. Para
eliminar tenga en cuenta hacer los corrimientos correspondientes y completar con ceros
al final.
Mi codigo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Clase08 {
final static int MAX = 10;
public static void main(String[] args) throws NumberFormatException, IOException {
int numeroingresado = 0;
int secuencia=0;
int numerodistintodecero=0;
int [] arreglo = new int[MAX];
cargadearreglo(arreglo, numeroingresado);
mostrarelarreglo(arreglo);
recorrerarreglo(arreglo, numerodistintodecero);
eliminarsecuencia(arreglo, secuencia);
}
private static void cargadearreglo(int[]arreglo,int numeroingresado) throws NumberFormatException, IOException {
BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
for(int i = 0; i <MAX; i++){
System.out.println("Completa el arreglo con numeros enteros: " + (i +1));
numeroingresado = new Integer(entrada.readLine());
arreglo[i] = numeroingresado;
}
}
private static void mostrarelarreglo(int[] arreglo) {
System.out.println("\nContenido del arreglo:\n");
for(int i: arreglo){
System.out.print( i + " ");
}
}
private static void recorrerarreglo(int[] arreglo, int numerodistintodecero) {
for(int i = 0; i <MAX; i++){
if(arreglo[i]!=0){
numerodistintodecero++;
}
else{
}
}
System.out.println("\nCantidad de numeros distintos de ceros: " + numerodistintodecero);
}
private static void eliminarsecuencia(int[] arreglo, int secuencia) throws NumberFormatException, IOException {
BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
System.out.println("\nCargar la secuencia de numeros distintos de cero que deseas eliminar:");
secuencia=new Integer(entrada.readLine());
}
}
Valora esta pregunta


0