I have the code below, where the user has to input 5 values in an array, and print out the same.
package Arrays;
import java.util.Scanner;
public class Arrays {
public static void main(String[] args) {
final int size=5;
Scanner input = new Scanner(System.in);
System.out.println("Enter the 5 number you want to be stored in an array");
int a[] =new int[size];
for(int i=0;i<a.length;i++){
a[i]=input.nextInt();
}
displayArray(a);
sumOfArray();
productOfArray();
smallAndLargeOfArray();
averageOfArray();
}
private static void displayArray(int arr[]) {
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i] + ' ');
}
}
}
here is my input:
1
2
3
4
5
and the output that I'm getting is:
33
34
35
36
37
Please let me know where I'm going wrong and how can I fix this.
charin java is really just an integer. When you writearr[i] + ' 'you are actually adding 2 numbers, not concatenating 2 strings.+ ' 'to+ " ".