You are here:   HomeJava ProgrammingJava ArrayDeleting Desire Element of Linked List Java Example
by Dinesh Thakur Category: array

Algorithm for Ones Present Inputted Array:

step 1: set arr_size,j, count as three static variables of integer type

step 2: read arr_size

step 3: create an integer array arr[] of size arr_size

step 4: initialize i=0 


step 5: repeat through step-7 while i less than arr_size

step 6: readarr[i]

step 7: i=i+ 1

step 8: initialize i=0

step 9: repeat through step-15 while i less than arr_size

step 10: j=arr[i]

step 11: repeat through step-14 while j greater than 0

step 12: k=j%10

step 13: if k equals to one then count=count+ 1

step 14:j=j/10

step 15: i=i+ 1

step 16: print count

step 17: Exit

Here is the Java Example for Ones Present Inputted Array:

import java.util.Scanner;
public class OnesPresentInputtedArray
              public static int size;
              public static int j;
              public static int count;
           public static void main(String args[])
              Scanner s=new Scanner(;
              System.out.print("Enter the Number of Elements :");
              int arr[]=new int[size];
              System.out.println("Enter the Elements : ");
              for(int i=0;i<size;i++)
                     System.out.println("Enter the "+i+"th Index Value");
                     for(int i=0;i<size;i++)
                                 int k=j%10;
System.out.print("No. of 1's Present in the Inputed Array is:-> ");

how many 1's are present in an inputted array

Subscribe To Free Daily Newsletter!

Get Free News Updates Delivered Directly To Your Inbox
About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to contact us.

What's New and Popular

Popular Article