[ Write a Program to input 10 numbers into an integer array and check whether all numbers are same or not.
Program Code :
import java.util.*;
class Same_Array_Element
{
public static void main(String args[])
{
int i,j,c=0,f=0;
int n[]=new int[10];
Scanner sc=new Scanner(System.in);
//Accepting 10 Array Element
for (i=0;i<10;i++)
{
System.out.print("Enter the Array Element = ");
n[i]=sc.nextInt();
}
for (i=0;i<10;i++)
{
//Checking All Array Element are same or not
if(n[i]==n[0])
c++; //Counting the same Element of an Array
}
if(c==10)
f=1; //if all the element same then f=1 or f=0
if(f==1)
System.out.println("All the Array Elements are Same");
else
System.out.println("All the Array Elements are Not Same");
}
}
No comments