Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ConvertNegativeToPositive {
- // Uses Math.abs to demonstrate converting a negative number
- // to a positive number.
- public static void main(String[] args) {
- int total = 2 + 2 + (-2);
- System.out.println("Total : " + total);
- int total2 = 2 + 2 + Math.abs(-2);
- System.out.println("Total 2 : " + total2);
- System.out.println("Positive numbers are returned unchanged : " + Math.abs(10));
- System.out.println("Negative numbers are returned as positive : " + Math.abs(-10));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment