I’m trying to make a program that solves equations, i want the answer to be displayed in the right way, if the number is negative, to display -x and not +-x,
for example,
Eq1: 4x-3 and not 4x+-3, but when it is positive to display 4x+3. I can’t use the plus sign inside the quotations.
I wanted to use the ? : operator.
I tried something like this
System.out.println("Eq1: "+ ((a11>0) ? (+ "+" + (int)a11) : + (int)a11) +"*x1+");
This line is supposed to print the negative number (i.e. it will be -2*x1) and if it’s positive it should display the + sign and add the number, but it gives me an error around the + “+” +
Any thoughts? Thanks!
I’d make the variable always positive, like so