Buonasera ragazzi...sono nuovo del forum, volevo chiedervi dove sbaglio in questo semplice programma : date due matrici, dice se la posizione di tutti i numeri negativi della prima matrice è uguale alla seconda...
Posto il codice:
//vedere se due matrici hanno i numeri negativi nelle stesse posizioni
import java.util.Scanner;
public class MatriceNeg{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("Digitare la dimensione della matrice quadrata,esempio: 3 se la si vuole 3X3");
int dim = sc.nextInt();
int M1[][] = new int[dim][dim];
System.out.println("Immettere i numeri da inserire nella matrice");
leggi(M1);
System.out.println("Ecco la matrice");
stampa(M1);
System.out.println();
int M2[][] = new int[dim][dim];
System.out.println("Immettere i numeri da inserire nella matrice "+dim+"*"+dim);
leggi(M2);
System.out.println("Ecco la matrice");
stampa(M2);
boolean neg=true;
while (M1[i][j]!=M1[M1.length-1][M1.length-1] && neg=true){
for(int i=0;i<M1.length;i++)
for(int j=0;j<M1.length;j++)
if(M1[i][j]<0){
if(M1[i][j]=M2[i][j])
neg=true;
else
neg=false;
}
if(neg)
System.out.println("La prima matrice ha la stessa posizione di numeri negativi della seconda");
else
System.out.println("La prima matrice non ha la stessa posizione di numeri negativi della seconda");
}
public static void leggi(int[][]M)
{Scanner sc = new Scanner(System.in);
for(int i=0;i<M[0].length;i++)
{for(int j=0;j<M.length;j++)
M[j][i] = sc.nextInt();
}
}
public static void stampa(int[][]M)
{for(int i=0;i<M[0].length;i++)
{for(int j=0;j<M.length;j++)
System.out.print(M[j][i]+" ");
System.out.println();
}
}
}
ed ecco gli errori:
D:\UNIVERSITA'\FONDAMENTI DI INFORMATICA\MatriceNeg.java:37: error: illegal start of expression
public static void leggi(int[][]M)
^
D:\UNIVERSITA'\FONDAMENTI DI INFORMATICA\MatriceNeg.java:37: error: illegal start of expression
public static void leggi(int[][]M)
^
D:\UNIVERSITA'\FONDAMENTI DI INFORMATICA\MatriceNeg.java:37: error: ';' expected
public static void leggi(int[][]M)
^
D:\UNIVERSITA'\FONDAMENTI DI INFORMATICA\MatriceNeg.java:37: error: '.class' expected
public static void leggi(int[][]M)
^
D:\UNIVERSITA'\FONDAMENTI DI INFORMATICA\MatriceNeg.java:37: error: ';' expected
public static void leggi(int[][]M)
^
D:\UNIVERSITA'\FONDAMENTI DI INFORMATICA\MatriceNeg.java:44: error: illegal start of expression
public static void stampa(int[][]M)
^
D:\UNIVERSITA'\FONDAMENTI DI INFORMATICA\MatriceNeg.java:44: error: illegal start of expression
public static void stampa(int[][]M)
^
D:\UNIVERSITA'\FONDAMENTI DI INFORMATICA\MatriceNeg.java:44: error: ';' expected
public static void stampa(int[][]M)
^
D:\UNIVERSITA'\FONDAMENTI DI INFORMATICA\MatriceNeg.java:44: error: '.class' expected
public static void stampa(int[][]M)
^
D:\UNIVERSITA'\FONDAMENTI DI INFORMATICA\MatriceNeg.java:44: error: ';' expected
public static void stampa(int[][]M)
^
D:\UNIVERSITA'\FONDAMENTI DI INFORMATICA\MatriceNeg.java:52: error: reached end of file while parsing
}
^
11 errors
Non capisco questi errori sulle funzioni!! che vanno benissimo in altri programmi.... Vi ringrazio per l'aiuto

