How to subtract two string arrays in java as they are shown in code -
//what should subtract quan
objin
? //means quan has values 1,2,7,9 , objin has values 5,6,7,8 how subtract result 4,4,0,1 want operation quan[]=quan[]-objin[] done?
public static void equalizer(int i, int s, string quan[], string objin[]) { int j; scanner inp = new scanner(system.in); for(j=0;j<i;j++) { system.out.print(objin[j]+"="); objin[j]=inp.nextline(); } for(j=0;j<s;j++) { system.out.print(quan[j]+"="); quan[j]=inp.nextline(); } }
there's subtract()
method
public string[] subtract(string[] sa1, string[] sa2){ list<string> r = new arraylist<>(); (int = 0; < sa1.length; i++){ if (i >= s2.length) { r.add(sa1[i]); continue; } try { r.add(string.valueof(integer.parseint(sa1[i]) - integer.parseint(sa2[i]))); } catch (parseexception e) { e.printstacktrace(); } } return r.toarray(new string[r.size()]); }
Comments
Post a Comment