Tuesday, December 23, 2014

Java short and Int to String and Array elements



Java short
                                                                                                           
public class JavaShortExample
{
  public static void main(String[] args)
{
short = ;
short s1 = 50;
short s2 = 42;
System.out.println("Value of short variable b1 is :" + s1);
System.out.println("Value of short variable b1 is :" + s2);
  }
}

Int to String

public class StringToIntJavaExample
{
public static void main(String args[])
{
int i = 11;
String str = Integer.toString(i);
System.out.println("int to String : " + i);
  }
}

Calculate Average value of Array elements

public class CalculateArrayAverageExample
{
public static void main(String[] args)
{
int[] numbers = new int[]{10,20,15,25,16,60,100};
int sum = 0;
for(int i=0; i < numbers.length ; i++)
sum = sum + numbers[i];
double average = sum / numbers.length;
System.out.println("Average value of array elements is : " + average);
   }
}

No comments:

Post a Comment