Please i need some help with this in Java! Submit another word document with you
ID: 3777401 • Letter: P
Question
Please i need some help with this in Java!
Submit another word document with your answers. Given the following: int i = 3; int [] arr = {10, 15, 7, 20, 11, 2}; int x = -1; int y = 100; Show the values in x and y after executing each of the following x = arr[3]; x = 2 * arr[0]; x = arr[1] + arr[2]; x = arr[i] + i; y = x + a [5]; x = arr[i] + 1; y = arr[i+1]; Given the following array: int[] a = new int [10]; Write a loop to do each of the following: Add 1 to every element of a. Count the number of negative numbers in a. Create a new array b which is the same size as a, and copy all elements from a into b. Print the elements of a in reverse order. Count the number of elements in a that have values between 10 and 20 inclusive.Explanation / Answer
Answers:
1. x = arr[3]; will give x value 20
2. x = 2 * arr[0]; will give x value 20
3. x = arr[1]+ arr[2]; will give x value 22
4. x = arr[i]+i;
y = x + arr[5]; will give x value 23 and y valule 25
5. x = arr[i]+1;
y = arr[i+1]; will give x vallue 21 and y value 11
6. Add 1 to every element of a
for(int i=0; i<a.length; i++){
a[i] = a[i] + 1;
}
7. count the number of negative numbers in a
int negCount = 0;
for(int i=0; i<a.length; i++){
if(a[i] < 0){
negCount++;
}
}
Question 8.
int []b= new int[a.length];
for(int i=0; i<a.length; i++){
b[i] = a[i];
}
Question 9:
for(int i=a.length-1;i>=0; i++){
System.out.println(a[i]);
}
Question 10:
int count = 0;
for(int i=0; i<a.length; i++){
if(a[i] >=10 && a[i] <= 20){
count++;
}
}