Go to Top

Friday, 21 October 2011

To find absolute value of an integer

Question 63 : Write a program in Java to find the absolute value of an integer.

Java Program :

class absolute
{
    static void cal(int a)
    {
        int b=a>0?a:-a;
        System.out.print("The absolute value of '"+a+"' : "+b);
    }
}

3 comments:

  1. Math.abs() would do the same work for you.

    ReplyDelete
  2. Well explained string operation .
    there are good String program collection visit More Java Example

    ReplyDelete

ShareThis