algorithms.tutorialhorizon.com

Print Number with its Sign in Java. | Algorithms

Sometimes we need to print the numbers with its sign irrespective of number is positive (+) or negative(-). Example: X = 5, print = +5 Y = -8, print = -8 Say we need to print a equation : 2x - 3y - 6 = 0 and if you will use System.out.println("Equation: "+ a + "x + " +b+ "y + " + c ); The output will be 2x + -3y + -6 which is wrong.