Anonymous Array in Java
Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java
Program 1
class TestAn
{
void display(int a[],int s)
{
int f=0;
for(int i=0;i<a.length;i++)
{
if(a[i]==s)
{
f=1;
break;
}
}
if(f==1)
System.out.println("Searching success");
else
System.out.println("Searching not success");
// int sum=0;
// for(int i=0;i<a.length;i++)
// {
// System.out.println(a[i]);
// sum=sum+a[i];
// }
// System.out.println(sum);
}
}
class TestAnonymous
{
public static void main(String args[])
{
TestAn T=new TestAn();
T.display(new int[] {10,20,30,40,50},20);
}
}Program 2
class TestAn1
{
int[] show()
{
return (new int[]{100,20,300,400,500});
}
}
class TestAnonymous1
{
public static void main(String args[])
{
TestAn1 T1=new TestAn1();
int ar[]=T1.show();
for(int i=0;i<ar.length;i++)
System.out.println(ar[i]);
}
}
Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

