Working out the output values
in
Programming Questions
•
1 year ago
Hi.
I'm really nervous about taking my first exam tomorrow on Processing .
I struggle with questions that require output values to be written out. I am wondering if someone would be kind enough to explain what mental steps, procedures or questions one should take when faced with these sorts of questions. I thought I knew the process of loops but sometimes I just get confused with the more complicated ones.
Thanks.
I'm really nervous about taking my first exam tomorrow on Processing .
I struggle with questions that require output values to be written out. I am wondering if someone would be kind enough to explain what mental steps, procedures or questions one should take when faced with these sorts of questions. I thought I knew the process of loops but sometimes I just get confused with the more complicated ones.
Thanks.
- //1.
String[] myArray = split("shoes and ships and ceiling wax and cabbages and kings", ' ');
String[][] myOtherArray = new String[3][3];
int index = 1;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
myOtherArray[i][j] = myArray[index];
index++;
}
println(myOtherArray[2][0]);
}
-------------------------------------
//2.
int x = 0;
for (int i = 0; i < 10; i++)
if (i % 2 == 0) {
x += 5;
println(x);
}
------------------------------------
//3.
for (int i = 1; i <= 5; i++)
for (int j = 10; j > i; j--)
statement;
------------------------------------
//4.
String[] myArray = {"hello", "there", "folks", "this", "is", "a", "test"};
String accum = "";
for(int i = myArray.length -1; i > 0; i--) {
accum = myArray[i] + accum;
}
println(accum); length
----------------------------------- - //5
int[] myArray = {1,2,3,4,5,6,7,8,9};
for (int i = 5; i >=0; i--) {
myArray[i] += myArray[i + 1];
println(myArray[i]);
}
1