When ordering the arithmetic symbols the "-" symbol is not printed

0

hello I was asked that when arithmetic symbols are entered after they were printed ordered by priority, update the code for an error that I do not know but when printing the variables I get null

package sig_ar_ord;

import java.util.Scanner;

public class Sig_ar_ord {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String[] s_a=new String[8];
String[] sa=new String[8];
String[] s_a_o={"[","]","(",")","*","/","%","+","-"};
 int x=0;
String aux;
     //0[ 1] 2( 3)
     //4* 5/ 6%
     //7+ 8-
for (int i = 0; i <4; i++) {
    System.out.println("Escribe el signo aritmetico ");
    s_a[i]=sc.next();

}

for (int i = 0; i < 4; i++) {
    for (int j = 0; j <8; j++) {
        if (s_a[i].equals(s_a_o[j])) {
            sa[j]=s_a[i];
        }
    }

}
System.out.println("Los simbolos en orden son:");
for (int i = 0; i <8; i++) {
   if(sa[i]!=null) {
       System.out.println(sa[i]);
   }

}



}

}
    
asked by Eduardo Quezada 04.10.2018 в 04:59
source

1 answer

0

You have an error in the order you are assigning to a wrong reference

Change

s_a [j] = sa [x];

By

sa [x] = s_a [j];

    
answered by 04.10.2018 в 06:12