Advertisement
Waliullah8328

Positive Negative Separate (In Array)

Feb 2nd, 2021
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class PositiveNegative {
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.         int n,i;
  9.         System.out.print("How many number you want to insert: ");
  10.         n = input.nextInt();
  11.         int arr[] = new int [n];
  12.  
  13.         System.out.println("---------------Enter your "+n+" Number------------------");
  14.         for(i = 0;i < n; i++)
  15.         {
  16.             arr[i] = input.nextInt();
  17.         }
  18.         System.out.print("Positive Number: ");
  19.         for(i=0 ;i < n; i++)
  20.         {
  21.             if(arr[i]> 0)
  22.             {
  23.                 System.out.print(+arr[i]+" ");
  24.             }
  25.         }
  26.         System.out.println();
  27.         System.out.print("Negative Number: ");
  28.         for(i=0 ;i < n; i++)
  29.         {
  30.             if(arr[i]< 0)
  31.             {
  32.                 System.out.print(+arr[i]+" ");
  33.             }
  34.         }
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement