Java Program on Anonymous Array

Free Java courses with 37 real-time projects - Learn Java

Program 1

package dataflair;

class TestA
{
      void display(int ar[])
      {
          for(int m:ar)
              System.out.println(m);
      }
}
class TestB
{
    void fact(int n)
    {
        int f=1;
        while(n!=0)
        {
          f=f*n;
          n--;
        }
        System.out.println("Factorial is "+f);
    }
}
public class TestMain7 
{
    public static void main(String[] args) 
    {
        
        TestA T=new TestA();
        //int a[]={10,20,40,50,70,80};
        T.display(new int[]{10,20,40,50,70,80});
           TestB T1=new TestB();
           T1.fact(7);
           new TestB().fact(5);
    }
    
}

Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google

follow dataflair on YouTube

Leave a Reply

Your email address will not be published. Required fields are marked *