forked from deepdalsania/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeCast.java
More file actions
37 lines (30 loc) · 739 Bytes
/
TypeCast.java
File metadata and controls
37 lines (30 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package file;
import java.util.Scanner;
public class TypeCast {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("<< IMPLICIT CASTING >>");
int d = 50;
float f = d;
System.out.println("F : " + f);
System.out.println("<< EXPLICIT CASTING >>");
Scanner s = new Scanner(System.in);
System.out.println("Enter array size= ");
int n = s.nextInt();
int sum = 0;
int a[] = new int[n];
float avg;
System.out.println("Enter elements of array:");
for (int i : a) {
a[i] = s.nextInt();
sum = sum + a[i];
}
System.out.println("Sum is: " + sum);
avg = (float) sum / n;
System.out.println("Acverage is : " + avg);
s.close();
}
}