Question
Write a counter controlled loop to solve the following problems. Each one will involve an array (Even.java) Read 25 ints from the keyboard, and store
Write a counter controlled loop to solve the following problems. Each one will involve an array
- (Even.java) Read 25 ints from the keyboard, and store them in an array. Display "true" on the screen if there is an even number of even numbers among these. Otherwise, display "false".
CODE:
public static void main(String [] args) {
int [] x = new int[3];
int [] y = {3, 5, 9, 2};
x[2] = y[3];
x[0]++;
y[1] += y[2] * y[0];
int [] z = x;
x = y;
x[1] = 4;
}
}
public class Array-Length {
public static void main(String [] args) {
int [] x = new int[4];
int [] y = {};
int [] z = {0};
System.out.println("x has " + x.length + " elements");
System.out.println("y has " + y.length + " elements");
System.out.println("z has " + z.length + " elements");
}
}
public class Array-With-Loop1 {
public static void main(String [] args) {
int [] x = {-4, 9, 8, 2, -5, 7, 1};
for(int i=1; i x[i] += x[i-1]; // notice: += instead of = } } } public class Array-With-Loop2 { public static void main(String [] args) { int [] x = {-4, 9, 8, 2, -5, 7, 1}; for(int i=1; i x[i] = x[i-1]; } } } public class Array-With-Loop3 { public static void main(String [] args) { int [] x = {-4, 9, 8, 2, -5, 7, 1}; int val = 0; for(int i=1; i val = val + x[i]; } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started