Computer Science, asked by Anonymous, 2 months ago


\huge\sf\underline\red{Question}




WAP in Java to input a number and deduce if the
entered number is positive or negative.

☞note: I want program not explanation​

Answers

Answered by anindyaadhikari13
1

Required Answer:-

Question:

  • Write a program in Java to input a number and check if the entered number is positive or negative.

Solution:

Here comes the códe.

import java.util.*;

public class Number {

 public static void main(String[] args) {

    int n;

    Scanner sc=new Scanner(System.in);

    System.out.print("Enter an integer: ");

    n=sc.nextInt();

    if(n>0)

      System.out.println("Number is positive.");

    else if(n<0)

      System.out.println("Number is negative.");

    else

      System.out.println("Its zero.");

    sc.close();

 }

}

Logic:

  1. Take the number as input.
  2. Check if the number is greater than 0. If true, the number is positive. If not true, check if the number is less than 0 or not. If true, the number is negative or else, the number is zero.

Refer to the attachment for output ☑.

Attachments:
Answered by XxItsPriNcexX
2

\huge✎\fbox \orange{QUE} ST  \fbox\green{ION}☟

WAP in Java to input a number and deduce if the entered number is positive or negative.

\huge✍︎\fbox\orange{ÂŇ}\fbox{SW} \fbox\green{ÊŘ}:

Public Class CheckPositiveOrNegative

{

public static void main(String[] args)

{

//number to be check

int num=(Enter Any Number);

//checks the number is greater than 0 or not

if(num>0)

{

System.out.println("The number is positive.");

}

//checks the number is less than 0 or not

else if(num<0)

{

System.out.println("The number is negative.");

}

//executes when the above two conditions return false

else

{

System.out.println("The number is zero.");

}

}

}

 \footnotesize\bold\red{\overbrace{\underbrace \mathbb\blue{Please \:  Mark \:  As \:  The \:  Brainliest\: If\: It\: Satisfied\:You}}}

꧁Hopes so that this will help you,꧂

♥️With Love♥️

✌︎Thanking you, your one of the Brother of your 130 Crore Indian Brothers and Sisters.✌︎

\large\red{\underbrace{\overbrace\mathbb{\colorbox{aqua}{\colorbox{blue}{\colorbox{purple}{\colorbox{pink}{\colorbox{green}{\colorbox{gold}{\colorbox{silver}{\textit{\purple{\underline{\red{《❀PŘÎ᭄ŇCĒ✿》࿐}}}}}}}}}}}}}}

Similar questions
Math, 9 months ago