Copy the code below and put it in a class named APQuizJanuary.
/* Make the following changes and write down your answers WITH an explanation of how each piece of code works.
3: Change the input: String[] b={"hawk","iguana","jaguar","kite","lemur","maggot"};
Change the code in mystery3 to say
int c=a.length;
for(int i=0;i<a.length-1; i++)
if(a[i].length()>a[i+1].length())c--;
return c;
4: Change the input: int[] a={10,25,40,57,90,201};
Change the code to say
int c=0;
for(int i=0;i<a.length; i++)
if(a[i]%x==0)c++;
return c;
5: What is output with a call to mystery5(623)
Change the code to
if(x>0)mystery5(x/5);
System.out.print(x+" ");
6: Call mystery6(20). What is output?
Change the code to
if(n>0)mystery6(n-5);
System.out.print(n+" ");
8: Change String b[] = {"not", "the", "same","string","array"}; What is output?
Change the code to
String[] b={"this","is","fine"};
int n=b[0].length();;
stuff(n,b);
System.out.print(n+b[0]);
9: Change the code to
public static void printSport(double n){
System.out.print("hockey ");
printSport((int)(n));
}
public static void printSport(int n){
System.out.print("wrestling ");}
Change the input to printSport(7); What is output?
10: Change the code to these 2 different options. What happens for each? Try at least 3 different input options to test it. Record your results.
OPTION 1
if(a>b) mystery10(a,b-1);
if(b>a) mystery10(a-1,b);
System.out.println(a+" "+b);
OPTION 2
System.out.println(a+" "+b);
if(a<b) mystery10(a+1,b-1);
if(b<a) mystery10(a-1,b+1);
*/
/**
* Write a description of class APQuizJanuary here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class APQuizJanuary
{
public static void main(){
String[] b={"aardvark","banana","cougar","daikon","elephant","fog","get"};
System.out.print("3: "+mystery3(b));
System.out.println("");
int[] a={1,2,3,4,5,6,7,8,9,8,7,6,5,4,5,6,7};
System.out.print("4: "+doSomething(a,5));
System.out.println("");
System.out.print("5: ");mystery5(547);
System.out.println("");
System.out.print("6: ");mystery6(40);
System.out.println("");
System.out.print("8: ");main8();
System.out.println(" or error because of , or length");
System.out.print("9: ");printSport(3.5);
System.out.println("");
System.out.print("10: "); mystery10(3,7);
System.out.println("");
}
public static int mystery3(String a[]){
int c=0;
for(int i=0;i<a.length-1; i++)
if(a[i].length()>a[i+1].length())c++;
return c;
}
public static int doSomething(int[] a, int x){
int c=0;
for(int i=0;i<a.length; i++)
if(a[i]==x)c++;
return c;
}
public static void mystery5(int x){
System.out.print(x%10+" ");
if(x>0)mystery5(x/10);
System.out.print(x%10+" ");
}
public static void mystery6(int n){
if(n>0)mystery6(n-10);
System.out.print(n+" ");
}
public static void main8(){
int n=1;
String[] b={"this","is","fine"};
stuff(n,b);
//System.out.print(n,b[0]); syntax error
System.out.print(n+b[0]);
}
public static void stuff(int w, String[] x)
{
x[0]=w+"";
//w=x.length(); syntax error
w=x.length;
}
public static void printSport(double n){
System.out.print("football ");
printSport((int)(n));
}
public static void printSport(int n){
System.out.print("basketball ");
}
public static void mystery10(int a, int b){
if(a<b) mystery10(a,b-1);
if(b<a) mystery10(a-1,b);
System.out.println(a+" "+b);
}
}