Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/04/2011, 06:34
Cooltan
 
Fecha de Ingreso: febrero-2011
Ubicación: españa
Mensajes: 36
Antigüedad: 13 años, 2 meses
Puntos: 0
Exclamación guardar en lista una palabra en java

Hola buenas tengo un problemilla, estoy con un proyecto y necesito guardar la palabra en una lista al finalizar de tratarla. ejemplo
pongo la palabra "ALA"
el programa me dice la letra A se ha reptido 2 veces
se inserto el caracter A con dos repeticiones
la letra L se ha repetido 1 vez
se inserto el caracter L con 1 repeticion y desde aqui quiero guardarla en una lista y que me ponga " la palabra ALA se ha guardado en la lista". Como podria hacerlo, este es mi codigo:



import java.io.IOException;
import java.io.*;

class NInternal {

Node[] next;
}

class NList {

String w;
NList[] next;
}

class Node {

char c;
NInternal[] i = new NInternal[10];
NList e = new NList();
}

public class Arboljd {

static public char getChar() throws IOException {
char c = (char) System.in.read();
input();
return c;
}

static public void input() throws IOException {
while ((char) System.in.read() != '\n');
}

static public int initNode(Node n, char l) throws IOException {
// Inicializar el nodo a insertar
n.e = null;
n.c = l;
return 0;
}

static public int insertNode(char l, int r, Node root) throws IOException {
// Inicializar el nodo a insertar
Node newNode = new Node();
if (initNode(newNode, l) != 0) {
System.out.println("Fallo al inicializar el Nodo\n");
} else {
// En caso de que sea el primer nodo a insertar.
if (root == null) {
System.out.println("Se va a insertar el nodo raiz \n");
root = newNode;
} else { // Cualquier otro nodo despues del raiz.
}
}
return r;
}

public static void main(String[] args) throws IOException {

char res;
Node root;
String s = "";
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(input);

do {
System.out.println("Inserte una palabra y pulse ENTER");
try {
s = reader.readLine();
} catch (Exception e) {
}
System.out.println("Escribiste: " + s + "\n");
int n[];
n = new int[27];
int tam = s.length();
int index = 0;
int max = 0;
char l;
do {
l = s.charAt(index);
switch (l) {
case 'a':
n[0]++;
if (max < 0) {
max = 0;
}
break;
case 'b':
n[1]++;
if (max < 1) {
max = 1;
}
break;
case 'c':
n[2]++;
if (max < 2) {
max = 2;
}
break;
case 'd':
n[3]++;
if (max < 3) {
max = 3;
}
break;
case 'e':
n[4]++;
if (max < 4) {
max = 4;
}
break;
case 'f':
n[5]++;
if (max < 5) {
max = 5;
}
break;
case 'g':
n[6]++;
if (max < 6) {
max = 6;
}
break;
case 'h':
n[7]++;
if (max < 7) {
max = 7;
}
break;
case 'i':
n[8]++;
if (max < 8) {
max = 8;
}
break;
case 'j':
n[9]++;
if (max < 9) {
max = 9;
}
break;
case 'k':
n[10]++;
if (max < 10) {
max = 10;
}
break;
case 'l':
n[11]++;
if (max < 11) {
max = 11;
}
break;
case 'm':
n[12]++;
if (max < 12) {
max = 12;
}
break;
case 'n':
n[13]++;
if (max < 13) {
max = 13;
}
break;
case '±':
n[14]++;
if (max < 14) {
max = 14;
}
break;
case 'o':
n[15]++;
if (max < 15) {
max = 15;
}
break;
case 'p':
n[16]++;
if (max < 16) {
max = 16;
}
break;
case 'q':
n[17]++;
if (max < 17) {
max = 17;
}
break;
case 'r':
n[18]++;
if (max < 18) {
max = 18;
}
break;
case 's':
n[19]++;
if (max < 19) {
max = 19;
}
break;
case 't':
n[20]++;
if (max < 20) {
max = 20;
}
break;
case 'u':
n[21]++;
if (max < 21) {
max = 21;
}
break;
case 'v':
n[22]++;
if (max < 22) {
max = 22;
}
break;
case 'w':
n[23]++;
if (max < 23) {
max = 23;
}
break;
case 'x':
n[24]++;
if (max < 24) {
max = 24;
}
break;
case 'y':
n[25]++;
if (max < 25) {
max = 25;
}
break;
case 'z':
n[26]++;
if (max < 26) {
max = 26;
}
break;
default:
break;
}
index++;
} while (index < tam);

System.out.println("La ultima letra es la numero: " + max);

for (index = 0; index <= max; index++) {
if (insertNode((char)n[index],index, root) != 0) {
System.out.println("Se inserto el caracter " + index + " con: " + n[index] + " repeticiones");
}
if (n[index] != 0) {
System.out.println("Cantidad de letras " + index + " en la frase es:" + n[index]);
}
}

//exter[mayor] = mayor;
System.out.println("┐Quiere insertar otra palabra? S/N");
res = getChar();

} while (res != ('n'));
}
}