0
Code:
public class Matrix {
public static void main(String[] args) {
Menu();
}
private static void Menu() {
CreateMatrix creatematrix = new CreateMatrix();
int escalar = 0;
int option = 0;
Scanner op = new Scanner(System.in);
do{ System.out.println(" \n\n##################### Matrix Calculator – ###################");
System.out.println("\n ==============================================");
System.out.println(" | 1 - Add two matrices |");
System.out.println(" | 2 - Subtract Matrices |");
System.out.println(" | 3 - Scalar Multiplication of a Matrix |");
System.out.println(" | 4 - Multiply two matrices |");
System.out.println(" | 0 - QUIT PROGRAM |");
System.out.println(" ==============================================\n");
System.out.print("\n");
option = op.nextInt();
switch(option){
case 0:
System.out.println("User Finished Program");
break;
case 1:
break;
case 2:
System.out.println("Subtract Matrices");
chamarMatrizdivisao();
break;
case 3:
System.out.println("Scalar Multiplication of a Matrix");
System.out.println("Digite o escalar: ");
escalar = op.nextInt();
break;
case 4:
System.out.println("Multiply two matrices");
chamarMatrizMultiplicacao();
break;
default:
System.out.println("Invalid option!!!");
}
}while (option !=0);
System.out.println("Invalid value ou Program is being closed");
}
public static void chamarMatrizMultiplicacao(){
Conteudo oConteudo = new Conteudo();
List<String> lista = oConteudo.Matriz();
oConteudo.MultiplicacaoMatriz22(lista);
}
public static void chamarMatrizdivisao(){
Conteudo oConteudo = new Conteudo();
List<String> lista = oConteudo.Matriz();
oConteudo.DivisaoMatriz22(lista);
}
}
I am asking the user to type the scalar and I want to take this variable to my class and deal with the method that follows below:
public void EscalarMatriz22(List<String> conteudo){
Matrix mtx = new Matrix();
int[] NumerosMatrizesEscalar = new int[conteudo.size()];
for (int ndxv = 0; ndxv < conteudo.size(); ndxv++) {
try{
int numv = Integer.parseInt(conteudo.get(ndxv));
NumerosMatrizesEscalar[ndxv] = Integer.parseInt(conteudo.get(ndxv));
} catch(Exception eox){
}
}
int div11 = NumerosMatrizesEscalar[2] - NumerosMatrizesEscalar[9];
int div12 = NumerosMatrizesEscalar[4] - NumerosMatrizesEscalar[10];
int div21 = NumerosMatrizesEscalar[3] - NumerosMatrizesEscalar[11];
int div22 = NumerosMatrizesEscalar[5] - NumerosMatrizesEscalar[12];
System.out.println(div11);
System.out.println(div12);
System.out.println(div21);
System.out.println(div22);
}
What I want is to get what the user typed in this part of the code
case 3:
 System.out.println("Scalar Multiplication of a Matrix");
 System.out.println("Digite o escalar: ");
 escalar = op.nextInt();
 break;
this scalar variable I want to take to the other class of my methodpublic class Conteudo {public void EscalarMatriz22(List<String> conteudo){

– Jéssica Developer
Your idea is to call this function after the value is read? You could modify the function to pass one more parameter, for example: public void Scalarmatriz22(List<String> content, int scalar) That would be the question?
– Luis Faconi
That’s right, however I’m not able to do it, always gives error in when trying to add int scalar.
– Jéssica Developer
Are you changing both the creation part of Function, and the part where you call it? If possible attach the error that returns you, maybe I can help you.
– Luis Faconi