Java - ayuda con codigo java

 
Vista:

ayuda con codigo java

Publicado por Juan José Ponce Torres (2 intervenciones) el 15/01/2013 23:21:36
VERAN LO QUE PASA ES QUE EL CODIGO SE COMPILA Y SE EJECUTA PERO EL PROBLEMA ES QUE SOLO SUMA....AYUDA

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import javax.swing.JOptionPane;
public class vectores2
{
public static void main(String[] args)
{
String res;
String opciones[]={"Suma","Resta","Multiplicacion","Division","Promedio","Escalar"};
 
int i,cant,dato,variable;
String scant,sdato,stotal="";
 
int[] vectora=new int [10];
int[] vectorb=new int [10];
int[] vectorc=new int [10];
 
res=(String) JOptionPane.showInputDialog(null,"Selecciona","la operacion",JOptionPane.INFORMATION_MESSAGE,null,opciones,opciones[0]);
//opciones[3] es el indice donde tiene que inicializar la lista ya sea con otro numero
 
 
if(opciones[2]=="Suma")
{
scant=JOptionPane.showInputDialog("INGRESE EL TAMAÑO DEL VECTOR");
cant=Integer.parseInt (scant);
if (cant<=0 ||cant>10) {
JOptionPane.showMessageDialog(null, "EL TAMAÑO MAXIMO ES 10");
}else
for(i=1;i<=cant;i++) {
sdato=JOptionPane.showInputDialog("INGRESE EL " + i + " NUMERO DEL VECTOR A");
dato=Integer.parseInt(sdato);
vectora[i]=dato;
}
for(i=1;i<=cant;i++) {
sdato=JOptionPane.showInputDialog("INGRESE EL " + i + " NUMERO DEL VECTOR B");
dato=Integer.parseInt(sdato);
vectorb[i]=dato;
}
for(i=1;i<=cant;i++) {
vectorc[i]=vectora[i]+vectorb[i];
stotal+=""+vectorc[i];
}
JOptionPane.showMessageDialog(null, "LA SUMA DE LOS VECTORES ES:"+stotal);
} else
if(opciones[1]=="Resta")
{
scant=JOptionPane.showInputDialog("INGRESE EL TAMAÑO DEL VECTOR");
cant=Integer.parseInt (scant);
if (cant<=0 ||cant>10) {
JOptionPane.showMessageDialog(null, "EL TAMAÑO MAXIMO ES 10");
}else
for(i=1;i<=cant;i++) {
sdato=JOptionPane.showInputDialog("INGRESE EL " + i + " NUMERO DEL VECTOR A");
dato=Integer.parseInt(sdato);
vectora[i]=dato;
}
for(i=1;i<=cant;i++) {
sdato=JOptionPane.showInputDialog("INGRESE EL " + i + " NUMERO DEL VECTOR B");
dato=Integer.parseInt(sdato);
vectorb[i]=dato;
}
for(i=1;i<=cant;i++) {
vectorc[i]=vectora[i]-vectorb[i];
stotal+=""+vectorc[i];
}
JOptionPane.showMessageDialog(null, "LA RESTA DE LOS VECTORES ES:"+stotal);
} else
if(opciones[2]=="Multiplicacion")
{
scant=JOptionPane.showInputDialog("INGRESE EL TAMAÑO DEL VECTOR");
cant=Integer.parseInt (scant);
if (cant<=0 ||cant>10) {
JOptionPane.showMessageDialog(null, "EL TAMAÑO MAXIMO ES 10");
}else
for(i=1;i<=cant;i++) {
sdato=JOptionPane.showInputDialog("INGRESE EL " + i + " NUMERO DEL VECTOR A");
dato=Integer.parseInt(sdato);
vectora[i]=dato;
}
for(i=1;i<=cant;i++) {
sdato=JOptionPane.showInputDialog("INGRESE EL " + i + " NUMERO DEL VECTOR B");
dato=Integer.parseInt(sdato);
vectorb[i]=dato;
}
for(i=1;i<=cant;i++) {
vectorc[i]=vectora[i]*vectorb[i];
stotal+=""+vectorc[i];
}
JOptionPane.showMessageDialog(null, "LA MULTIPLICACION DE LOS VECTORES ES:"+stotal);
} else
if(opciones[3]=="Division")
{
scant=JOptionPane.showInputDialog("INGRESE EL TAMAÑO DEL VECTOR");
cant=Integer.parseInt (scant);
if (cant<=0 ||cant>10) {
JOptionPane.showMessageDialog(null, "EL TAMAÑO MAXIMO ES 10");
}else
for(i=1;i<=cant;i++) {
sdato=JOptionPane.showInputDialog("INGRESE EL " + i + " NUMERO DEL VECTOR A");
dato=Integer.parseInt(sdato);
vectora[i]=dato;
}
for(i=1;i<=cant;i++) {
sdato=JOptionPane.showInputDialog("INGRESE EL " + i + " NUMERO DEL VECTOR B");
dato=Integer.parseInt(sdato);
vectorb[i]=dato;
}
for(i=1;i<=cant;i++) {
vectorc[i]=vectora[i]/vectorb[i];
stotal+=""+vectorc[i];
}
JOptionPane.showMessageDialog(null, "LA DIVISION DE LOS VECTORES ES:"+stotal);
}
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Jhonnathan Emilio Cardona Saineda

ayuda con codigo java

Publicado por Jhonnathan Emilio Cardona Saineda (328 intervenciones) el 16/01/2013 15:29:08
en vez de (opciones[1]=="suma" ) Tienes que colocar en todas las decisiones res.equals("suma").
PD: El código esta mas complejo comparado con este simple error
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

ayuda con codigo java

Publicado por Juan José Ponce Torres (2 intervenciones) el 16/01/2013 23:34:47
muchas gracias me ayudo lo que me dijiste y ya corregi los demas errores recien estoy aprendiendo!!!
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de ANALIA

ayuda con codigo java

Publicado por ANALIA (18 intervenciones) el 16/01/2013 15:54:28
Hola !!!, lo esta escriviendo en el Netbeans. ?
Bueno te digo el problema es que no realizas las operaciones y las mostras.
Saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar