in Java - Create a folder called pgm1 - In your folder pgm1, USING A WINDOWS EDI
ID: 3879669 • Letter: I
Question
in Java
- Create a folder called pgm1
- In your folder pgm1, USING A WINDOWS EDITOR, create a java program named
Your lastName, firstLetterOfYourFirstName, pgm1W.java that will do the following:
Start here
- From your main method call a new method named: processArray
- In the processArray method, create one 10x10 two dimensions array named twoDarray
- In each index of your twoDarray, load the multiplication of its corresponding xy locations
- Using the printf java command display, in a perfect square, the even values found
in your array's locations
In the square locations where the values are nor even, display 2 blank spaces("--")
The final result need to print out a PERFECT square.
Only the output needs to be a perfect square shape, the numbers in the outout need to only be even(all the even numbers that result from (x*y)). All the odd numbers from x*y need to be replaced by 2 blank spaces. The 0 shoulndt matter, in my code having the 0 or having it replaced by 2 spaces make no diffrence. (Would be great(not required) if there was only 1 for loop in the code, I can't figure out how to make it only 1 for loop and make it in perfect square shape)
Explanation / Answer
public class matrixprinting {
public static void main(String[] args) {
processarray();
}
/** returns the minimum of two numbers */
public static int processarray() {
int k;
int[][] twoDarray = new int[10][10];
String b = ("--");
for(int i = 0; i < 10; i++) {
for(int j = 0; j < 10; j++) {
twoDarray[i][j] = i * j;
}
}
for(int i = 0; i < 10; i++) {
for(int j = 0; j < 10; j++) {
k = twoDarray[i][j];
if(k % 2 == 0) {
//a[i][j]=b[1];
System.out.print(twoDarray[i][j] + " ");
} else {
System.out.print("-- ");
}
}
System.out.println();
}
return 0;
}
}
Please let me know if you need something from my end on the same.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.