Write a Java -program to print Unary Minus Operation?

Write a Java -program to print Unary Minus Operation


class Main
{
    public static void main(String args[])
    {
        int x=10;
        System.out.println("The sign value is "+(-x));
    }
}	
                                            

Output:

The sign value is -10




Using commandLine arguments

class Main
{
    public static void main(String args[])
    {
        int x;
        x=Integer.parseInt(args[0]);
        System.out.println("The Sign value is "+(-x));
    }
}
                                            

Output:

The sign value is -10




Using Scanner class

import java.util.*;
class Main
{
    public static void main(String args[])
    {
        int x;
        Scanner s=new Scanner(System.in);
        System.out.println("Enter x value ");
        x=s.nextInt();
        System.out.println("The Sign value is "+(-x));
}
}
                                            

Output:

Enter x value 10
The sign value is -10







More Programs


1 . Unary Minus Program
2 . PreIncrement Program
3 . PostIncrement Program
4 . PreDecrement Program
5 . PostDecrement Program
6 . Addition Program
7 . Substraction Program
8 . Multiplication Program
9 . Division Program
10 . Modular Division Program