This program takes an input array from the user and then prints out the positive elements of the array. Here's how it works:
Note: This program does not handle invalid user inputs such as non-numeric inputs or negative array limits. It also does not handle the case where the array has no positive elements.
import java.util.Scanner; class ArrayNum_Positive { public static void main(String[] args) { Scanner input =new Scanner(System.in); System.out.print("Enter the Array Limit :"); int l =input.nextInt(); int [] a =new int[l]; for(int i=0;i<l;i++) { System.out.printf("Element of a[%d] :",i); a[i]=input.nextInt(); } System.out.println("\nPositive Array Elements...\n"); for(int p:a) { if(p>0) System.out.println(p); } } }
Enter the Array Limit :5 Element of a[0] :67 Element of a[1] :-4 Element of a[2] :3 Element of a[3] :-5 Element of a[4] :44 Positive Array Elements... 67 3 44
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions