Computer Science, asked by akshaytechie001, 1 day ago

Write a Java program to input a number, check it is Negative, Positive or Zero.
(using if else if statement).
Input: 67 Output: Positive
Input: -357 Output : Negative

Answers

Answered by Anonymous
0

Answer:

import java.util.Scanner;

class TypeOfNumber

{

public static void main(String[] args)

{

//Declaration

Scanner input = new Scanner(System.in);

int number;

//Prompt and accept an integer from user

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

number = input.nextInt();

//Display the type of integer

if (number > 0)

{

        System.out.println(number + " : Positive");

}

if (number < 0)

{

        System.out.println(number + " : Negative");

}

{

        System.out.println(number + " : Zero");

}

}

}

Answered by anindyaadhikari13
4

\textsf{\large{\underline{Solution}:}}

The given problem is solved using language - Java.

import java.util.Scanner;

public class Number{

   public static void main(String args[]){

       System.out.print("Enter a number: ");

       int a=(new Scanner(System.in)).nextInt();

       if(a>0)

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

       else if(a<0)

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

       else

           System.out.print("Number is zero.");

   }

}

\textsf{\large{\underline{Logic}:}}

  1. Accept the number from the user, say a.
  2. Check if a > 0. If true, number is positive. If false, check if a < 0 or not. If true, number is negative or else, its zero.

See attachments for output.

Attachments:
Similar questions