Computer Science, asked by lilsupah7400, 11 months ago

Write a program in java to input a number from user .if the number is negative than convert it into positive number and vice versa .print proper message

Answers

Answered by sswaraj04
0

Answer:

import java.util.Scanner;

public class HelloWorld{

    public static void main(String []args){

        Scanner sc=new Scanner(System.in);

       

       System.out.println("Enter the number");

       int n=sc.nextInt();

       if(n>0)

       System.out.println("Number entered is "+n+".It's positive it's negative is "+-1*n);

       if(n<0)

       System.out.println("Number entered is "+n+".It's negative it's positive is "+-1*n);

       if(n==0)

       System.out.println("Number entered is"+n);

    }

}

Explanation:

simply check n>0 ,<0 or =0

and print message accordingly

Similar questions