Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

2.

A. SUM OF ELEMENET OF ARRAY:


public class SumArray
{
public static void main(String[] args)
{
int[] num={10,20,15,30,25};
int sum=0;
for(int i=0;i<num.length;i++)
{
sum=sum+num[i];
}
System.out.println("sum of array is"+ sum);
}
}
OUTPUT:

B.SMALLEST ELEMENET OF AN ARRAY:


public class SArray
{
public static void main(String[] args)
{
int[] myList ={10,20,12,15,23};
for(int i =0; i < myList.length; i++)
{
System.out.println(myList[i]+" ");
}
int total =0;
for(int i =0; i < myList.length; i++)
{
total += myList[i];
}
System.out.println("Total is "+ total);
double min = myList[0];
for(int i =1; i < myList.length;i++)
{
if(myList[i]< min)
min = myList[i];
}
System.out.println("largest element in array is "+ min);
}
}
OUTPUT:

C.LARGEST ELEMENT OF AN ARRAY:


public class TestArray
{
public static void main(String[] args)
{
int[] myList ={10,20,12,15,23};
for(int i =0; i < myList.length; i++)
{
System.out.println(myList[i]+" ");
}
int total =0;
for(int i =0; i < myList.length; i++)
{
total += myList[i];
}
System.out.println("Total is "+ total);
double max = myList[0];
for(int i =1; i < myList.length;i++)
{
if(myList[i]> max)
max = myList[i];
}
System.out.println("largest element in array is "+ max);
}
}
OUTPUT:
4:
A.
public class Counter
{
int count=0;
Counter()
{
count++;
System.out.println(count);
}
public static void main(String args[])
{
Counter c1=new Counter();
Counter c2=new Counter();
Counter c3=new Counter();
}
}
Output:
B:
public class Counte
{
static int count=0;
Counte()
{
count++;
System.out.println(count);
}
public static void main(String args[])
{
Counte c1=new Counte();
Counte c2=new Counte();
Counte c3=new Counte();
}
}

You might also like