Fórum Vetor/Array de Char como utilizar?? #569077
03/06/2009
0
import javax.swing.JOptionPane;
public class R11 {
public static void main(String[] args) {
int[] va, vb;
va = new int[20];
vb = new int[20];
String[] vo = new String[20];
double[] vc;
vc = new double[20];
String sva, svb;
char svo;
for(int i = 0; i<=19; i++){
sva = JOptionPane.showInputDialog(null, "Digite os valores dos vetores de A de 1 ate 20");
va[i] = Integer.parseInt(sva);
}
for(int i = 0; i<=19; i++){
svb = JOptionPane.showInputDialog(null, "Digite os valores dos vetores de B de 1 ate 20");
vb[i] = Integer.parseInt(svb);
}
for(int j = 0; j<=19; j++){
svo = JOptionPane.showInputDialog(null, "Digite as operações a serem feitas com os vetores de A e B de 1 ate 20");
vo[j] = char.parsechar(svo); // aqui ocorre um erro, como se insere valores dentro de um vetor com char?
}
for(int l = 0; l<=19; l++){
vc = Double.parseDouble(vc);
if (vo[l] == +){
vc[l] = va[l] + vb[l];
}else if(vo[l] == "-"){
vc[l] = va[l] - vb[l];
}else if (vo[l] == "*"){
vc[l] = va[l]*vb[l];
}else{
vc[l] = va[l]/vb[l];
}
}
}Vinicius Santos
Curtir tópico
+ 0Posts
04/06/2009
Thiago Silva
Gostei + 0
05/06/2009
Vinicius Santos
Gostei + 0
06/06/2009
Ricardo Viana
String[] vo = new String[20];
for(int j = 0; j<=19; j++){
svo = JOptionPane.showInputDialog(null, "Digite as operações a serem feitas com os vetores de A e B de 1 ate 20");
vo[j] = String.valueOf(svo); // aqui você armazena o seu "char", mas chamando o valueOf do método String (transformando o char em String).
}
Gostei + 0
06/06/2009
Vinicius Santos
for(int l = 0; l<=19; l++){
if (vo[l] == +){ //essa aplicação não é valida porque?
vc[l] = va[l] + vb[l];
}else if(vo[l] == -){
vc[l] = va[l] - vb[l];
}else if (vo[l] == *){
vc[l] = va[l]*vb[l];
}else{
vc[l] = va[l]/vb[l];
}
}
Gostei + 0
06/06/2009
William Siqueira
for(int l = 0; l<=19; l++){
if (vo[l] == +){ //essa aplicação não é valida porque?
vc[l] = va[l] + vb[l];
}else if(vo[l] == -){
vc[l] = va[l] - vb[l];
}else if (vo[l] == *){
vc[l] = va[l]*vb[l];
}else{
vc[l] = va[l]/vb[l];
}
}
for(int l = 0; l<=19; l++){
if (vo[l] == '+'){ //essa aplicação não é valida porque?
vc[l] = va[l] + vb[l];
}else if(vo[l] == '-'){
vc[l] = va[l] - vb[l];
}else if (vo[l] == '*'){
vc[l] = va[l]*vb[l];
}else{
vc[l] = va[l]/vb[l];
}
}
Gostei + 0