for (int i=6; i>0; i++) {
System.out.println (i);
}
public class Test {
public static void main (String[] argv)
{
int i = 5;
int[] A = {6};
change (i);
System.out.println (i);
change (A[0]);
System.out.println (A[0]);
}
static void change (int i)
{
i = i + 1;
}
}
prints
for (int i=1; i<A.length; i++) {
A[i] = A[i-1];
}
System.out.println (Arrays.toString(A));
results in:
public class Test {
public static void main (String[] argv)
{
char[] letters = {'b','a','d','c','a','f','e'};
String s = strangeMethod (letters);
System.out.println (s);
}
static String strangeMethod (char[] A)
{
int base = (int) 'a';
String s = "";
for (int i=0; i<A.length; i++) {
int k = (int) A[i];
if (k < base+2) {
s = s + A[i];
}
}
return s;
}
}
This results in:
char[] letters = {'a','b','c','d','e','f'};
write a method called mixHalves
to return a string with all the
odd-positioned letters together followed the
even-positioned letters. Thus, for the above,
with the call
String s = maxHalves(letters);
System.out.println (s);
you should get bdface as the printed string.
int[] A = {1, 2, 3, 2, 1};
int[] B = {1, 4, 9, 9, 4, 1};
int[] C = {1, 4, 9, 6, 1};
System.out.println (checkPalindrome(A));
System.out.println (checkPalindrome(B));
System.out.println (checkPalindrome(C));
should print
true
true
false
Write the method checkPalindrome using only while-loops
(i.e., without for-loops).