Foros del Web » Programación para mayores de 30 ;) » Java »

Ayuda Arreglo String

Estas en el tema de Ayuda Arreglo String en el foro de Java en Foros del Web. Aqui esta el codigo , no me compila :( ayuda porfavor import java.io.*; import java.util.*; import java.util.Scanner; import javax.swing.*; class List { static int num ...
  #1 (permalink)  
Antiguo 01/04/2009, 10:13
 
Fecha de Ingreso: abril-2009
Mensajes: 1
Antigüedad: 15 años, 1 mes
Puntos: 0
Ayuda Arreglo String

Aqui esta el codigo , no me compila :( ayuda porfavor

import java.io.*;
import java.util.*;
import java.util.Scanner;
import javax.swing.*;

class List {

static int num = 6;
static int i;

static String arreglo[ ] = new String[num];

static Scanner scan = new Scanner(System.in)


public static void ingrese() {


for(i = 0; i < arreglo.length ; i++)
{

arreglo[i] = scan.toString();


}


}

public static void main (String[] args)

{

ingrese();
}

}

Saludos-
  #2 (permalink)  
Antiguo 01/04/2009, 10:56
Avatar de drac94  
Fecha de Ingreso: mayo-2008
Ubicación: México
Mensajes: 383
Antigüedad: 16 años
Puntos: 5
Respuesta: Ayuda Arreglo String

Hola, que error te arroja el compilador?

y en esta linea
Código PHP:
arreglo[i] = scan.toString(); 
no deberia ser

Código PHP:
arreglo[i] = scan.next(); 
Saludos
  #3 (permalink)  
Antiguo 01/04/2009, 10:58
Avatar de drac94  
Fecha de Ingreso: mayo-2008
Ubicación: México
Mensajes: 383
Antigüedad: 16 años
Puntos: 5
Respuesta: Ayuda Arreglo String

ah y te falta cerrar el scanner

Código PHP:
scan.close(); 
  #4 (permalink)  
Antiguo 01/04/2009, 17:02
Avatar de cptanalatriste  
Fecha de Ingreso: octubre-2008
Ubicación: Lima, Perú
Mensajes: 118
Antigüedad: 15 años, 6 meses
Puntos: 2
Respuesta: Ayuda Arreglo String

Ehh.. creo que te falta un punto y coma, después de:

static Scanner scan = new Scanner(System.in); //poner ese punto y coma

Con eso ya debería compilar

Saludos,

Carlos G. Gavidia
SCJP, SCWCD, SCBCD
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 10:02.