Make repeating numbers 0 and putting them at the beginning of array I am new to programming and I have made a program to make all repeating numbers in an array 0 and put those all 0s in left side:

import java.util.*;
class ArrayWork
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int arr[],n,i,j,nr[]= new int[5];
        System.out.println("Enter the value for n: ");
        n = sc.nextInt();
        if(n&gt;25)
            System.out.println("Invalid input");
        else
        {
            arr = new int[n]; 
            System.out.println("Enter the array elements: ");
            for(i=0;i&lt;n;i++)
            {
                arr[i] = sc.nextInt();
            }
            int count =0;
            for( i=0; i&lt; arr.length-1;i++)
            { for (j=i+1;j&lt;arr.length;j++)
                {if(arr[i]==arr[j])
                   nr[i]=arr[i];
                    System.out.println(nr[i]);
                }}
            for(int v=0;v&lt;n;v++){  for(i=0;i&lt;n;i++)
            {
                if(arr[i]==nr[v])
                {
                    for(j=i-1;j&gt;=0&amp;&amp;arr[j]&gt;0;j--)
                    {
                        arr[j+1]=arr[j];
                    }
                    arr[j+1]=0;
                }
            }}

            System.out.println("The array is: ");
            for(i=0;i&lt;n;i++)
            {
                System.out.print(arr[i] + " ");
            }
        }
    }

}


Can I do anything to make this program smaller although the output is coming right and the program is ok
but I have made many loop,
Hope you know any better way?

INPUT:

10,20,20,4,4,6


OUTPUT:

0,0,0,0,10,6
Declaration


  int arr[],n,i,j,nr[]= new int[5];



Consider to declare variables on separate lines. From Code Complete, 2nd Edition, p761:


  Use only one data declaration per line
  
  [...]
  
  It’s easier to modify declarations because each declaration is self-contained.
  
  [...]
  
  It’s easier to find specific variables because you can scan a single column rather than reading each line. It’s easier to find and fix syntax errors because the line number the compiler gives you has only one declaration >on it.


Unused Variables


  int count =0;



count gets declared and initialized but is never in use.. Unused variables should be removed. 

Magic Number


  Your code uses a number that has a certain meaning to it.


One magic number is hidden in the code.


  if(n&gt;25) {



You can create a new constant variable MAX_SIZE


  if(n&gt;MAX_SIZE) {
``



Formatting


  for( i=0; i&lt; arr.length-1;i++)
{ for (j=i+1;j&lt;arr.length;j++)
    {if(arr[i]==arr[j])
       nr[i]=arr[i];
        System.out.println(nr[i]);
    }}



The code has an inconsistent formatting. Some key words are on a new-line and some times on the same line of a {.

Additional the code is format in a more C-like style, which I respect but you should have a look into Oracles Code Conventions for the Java.

Reduce Code Complexity Via Methods

When we consider a Code Smell Metrics and look at the code, we will find at least two points, that apply:


  
  Methods with more than 20 lines of code 
  Methods with nesting more than 2 (?) levels deep 
  Any global or static variables
  


To reduce the complexity we can introduce some new methods. For example


  for(i=0;i&lt;n;i++)
{
    arr[i] = sc.nextInt();
}



can be wrapped into a method storeUserInput.