Array in java using argument for integer, character and string

class ex_4
{
    public static void main(int m[])
    {
        int i,sum;
        sum=0;
        int l=m.length;
        for(i=0;i<l;i++)
        sum+=m[i]; 
        System.out.println("Length of the array: "+l);
        System.out.println("the sum of the array elements ="+sum);
    }
}

output

Length of the array: 5
the sum of the array elements =15


class ex_5
{
    public static void main(char ch[])
    {
        int i;
        int l=ch.length;
        for(i=0;i<l;i++)
        System.out.println(ch[i]);
    }
}


class ex_6
{
    public static void main(String n[ ])
    {
        int i;
        int l=n.length;
        System.out.println("The names are:");
        for(i=0;i<l;i++)
        System.out.println(n[i]);
    }
}

No comments:

Post a Comment

any problem in any program comment:-

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...