Advertisement
mhrabbi

Print negative element in array (java)

Feb 12th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class NegativeArrPrint {
  5.    
  6.     public static void main(String args[])
  7.     {
  8.        
  9.         Scanner scan=new Scanner(System.in);
  10.        
  11.         int size;
  12.        
  13.         System.out.println("Enter the Size of array: ");
  14.         size=scan.nextInt();
  15.        
  16.        
  17.         int [] arr =new int[size];
  18.        
  19.        
  20.       System.out.println("Enter elements in array");
  21.      
  22.       for(int i=0; i<arr.length; i++)
  23.         {
  24.           arr[i]=scan.nextInt();
  25.         }
  26.       System.out.println("All negative elements in arry are");
  27.      
  28.       for(int i=0;i<arr.length;i++)
  29.       {
  30.           if(arr[i]<0)
  31.           {
  32.               System.out.println(arr[i]);
  33.           }
  34.       }
  35.       scan.close();
  36.        
  37.     }
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement