Ajuda!

8 respostas
cristianequeiroz1

Olhem meu codigo:

import javax.swing.JOptionPane;
class Exercicio7 {
	public static void main(String arg[]) {
		int A[][] = new int[3][2];
		int B[][] = new int[3][2];
		int C[][] = new int [3][2];
		
		for (int i = 0; i < 3; i++) {
			   for (int j = 0; j < 2; i++) {
			      String a = JOptionPane.showInputDialog(null, "Digite o valor A ["	+ i + "]");
			      A[i][j] = Integer.parseInt(a);
			   }
			}
		for (int i = 0; i < 3; i++) {
			   for (int j = 0; j < 2; i++) {
			      String b = JOptionPane.showInputDialog(null, "Digite o valor B ["+ i + "]");
			      B[i][j] = Integer.parseInt(b);
			   }
			}
		String saida = "";
		
		for (int i = 0; i < 3; i++) {
			   for (int j = 0; j < 2; i++) {
				   C [i][j]= A [i][j] + B [i][j];
				saida += "C[" +i+ "] =" + C[i] + "\n";
		}
	}
		JOptionPane.showMessageDialog (null, saida);
	}

Preciso que isso compile direito...
Nao nao rola...

Alguem pode me dar um a luz?

8 Respostas

Zeed01

Boa noite Colegas !

Qual o erro ?

[]s

Pela sua quantidade de mensagens me parece que é novo no GUJ, uma dica, se quiser receber mais ajuda comece colocando titulos mas significativos nas mensagens.

M
cristianequeiroz1:
Olhem meu codigo:
import javax.swing.JOptionPane;
class Exercicio7 {
	public static void main(String arg[]) {
		int A[][] = new int[3][2];
		int B[][] = new int[3][2];
		int C[][] = new int [3][2];
		
		for (int i = 0; i < 3; i++) {
			   for (int j = 0; j < 2; j++) {
			      String a = JOptionPane.showInputDialog(null, "Digite o valor A ["	+ i + "]");
			      A[i][j] = Integer.parseInt(a);
			   }
			}

Olá, dá uma olhada no seu for mais interno no incremento, você trocou o j pelo i.
Abraços.

cristianequeiroz1

Entao…
mais cedo eu postei e um colega daqui mesmo disse que eu teria q ter duas variaveis…
ai fiz isso…
O problema é o seguinte: Lê-se dois vetores A e B e da-se a soma dos dois em C.
O programa funciona so no comeco depois da erro

gpd38

De uma olhada e diga o que vc achou.

Não modifiquei muita coisa nao

import javax.swing.JOptionPane;
class Exercicio07 {
	public static void main(String arg[]) {
		int A[][] = new int[3][2];
		int B[][] = new int[3][2];
		int C[][] = new int [3][2];
		
		for (int i = 0; i < 3; i++) {
			   for (int j = 0; j < 2; j++) {
			      A[i][j] = Integer.parseInt(JOptionPane.showInputDialog("Digite o valor A ["	+ i + "] [ "+j+" ] "));
			   }
			}
	
		for (int i = 0; i < 3; i++) {
			   for (int j = 0; j < 2; j++) {
			      B[i][j] = Integer.parseInt(JOptionPane.showInputDialog("Digite o valor B ["+ i + "]"));
			   }
			}
		
		for (int i = 0; i < 3; i++) {
			   for (int j = 0; j < 2; j++) {
				   C [i][j]= A [i][j] + B [i][j];				
		}	   
	}
		//mostrar a matriz
		for (int i = 0; i < 3; i++) {
			   for (int j = 0; j < 2; j++) {
				   System.out.print(C [i][j]+" ");				
		}	
			   System.out.print("\n");
	}
		
	}
}
cristianequeiroz1

Valeu mesmooo!!!

Assim, eu posso fazer a mesma coisa com o vetor B ne?

cristianequeiroz1

Posso sim pois é so a msg!! derrr pra mim!!!

Gente mais uma vez OBRIGADO MESMO!!!

Bjux

Zeed01

Boa noite Colegas !

Se entendi seu problema, porque você precisa de um vetor de 2 dimensões ?

não seria:

import javax.swing.JOptionPane;   

class Exercicio7 {
    public static void main(String arg[]) {   
        int A[] = new int[3];   
        int B[] = new int[3];   
        int C[] = new int [3];   
           
        for (int i = 0; i < 3; i++) {   
            String a = JOptionPane.showInputDialog(null, "Digite o valor A [" + i +  "]");   
            A[i]= Integer.parseInt(a);   
            C[i] = 0;
        }   
        
        for (int i = 0; i < 3; i++) {   
            String a = JOptionPane.showInputDialog(null, "Digite o valor B [" + i +  "]");   
            B[i]= Integer.parseInt(a);   
        }   
        
        String saida = "Resultado: \n";
        for (int i = 0; i < 3; i++) {   
            C[i] += B[i] + A[i];
            saida += A[i] +  "+" + B[i] + "=" + C[i] + "\n";
        }           
        JOptionPane.showMessageDialog(null, saida);

    }   
}

[]s

gpd38

Sim

Versao um pouco melhor.

Vc pode fazer melhor ainda (ler o tam da matria a e b diferentes), so toma cuidado na hora de montar a c
A c nao vai ser do tamanho da linha e coluna e sim do tam da matriz a e do tamanho da matriz b

import javax.swing.JOptionPane;
class Exercicio07 {
	public static void main(String arg[]) 
	{
		int linha = Integer.parseInt(JOptionPane.showInputDialog("Numero de linhas da matriz"));
		int coluna = Integer.parseInt(JOptionPane.showInputDialog("Numero de colunas da matriz"));
		int A[][] = new int[linha][coluna];
		int B[][] = new int[linha][coluna];
		int C[][] = new int [linha][coluna];
		
		
		//**********************************************************
		//Matriz A
		for (int i = 0; i < linha; i++) 
		{
			for (int j = 0; j < coluna; j++) 
			{
				A[i][j] = Integer.parseInt(JOptionPane.showInputDialog("Digite o valor A ["+(i+1)+"] ["+(j+1)+"]"));
			}
		}
		//mostrar a matriz A
		System.out.println("MATRIZ A\n");
		for (int i = 0; i < linha; i++)
		{
			for (int j = 0; j < coluna; j++) 
			{
				System.out.print(A [i][j]+" ");
			}
			System.out.print("\n");
		}
		//**********************************************************
		//Matriz B
		for (int i = 0; i < linha; i++) 
		{
			for (int j = 0; j < coluna; j++) 
			{
				B[i][j] = Integer.parseInt(JOptionPane.showInputDialog("Digite o valor B ["+(i+1)+"] ["+(j+1)+"]"));
			}
		}
		//mostrar a matriz B
		System.out.println("\nMATRIZ B\n");
		for (int i = 0; i < linha; i++)
		{
			for (int j = 0; j < coluna; j++) 
			{
				System.out.print(B [i][j]+" ");
			}
			System.out.print("\n");
		}
		//**********************************************************
		//Matriz C
		for (int i = 0; i < linha; i++) 
		{
			for (int j = 0; j < coluna; j++) 
			{
				C [i][j]= A [i][j] + B [i][j];
			}
		}
		//mostrar a matriz C
		System.out.println("\nMATRIZ C\n");
		for (int i = 0; i < linha; i++)
		{
			for (int j = 0; j < coluna; j++) 
			{
				System.out.print(C [i][j]+" ");
			}
			System.out.print("\n");
		}
	
	}//main
}//class
Criado 23 de abril de 2008
Ultima resposta 23 de abr. de 2008
Respostas 8
Participantes 4