Access Millions of academic & study documents

2 Trace the following part of codes step by ste, show eacly what wil

Content type
User Generated
Showing Page:
1/3
2. Trace the following part of codes step by ste, show
eacly what will prat methods as requested public class
Final2 t public static void main (String arg) int []x = new
int[21] int y: for (y = 8; y
Solution
first it will print \"I\'m in main\".
then it will print 0 because after completing the loop value
of y will be 15 and x[15] =0.
then it will print \"I\'m in PrintFirst\"
and then values at index from 8 to 14
then it will print \"I\'m in PrinChar\"
then it will print all the char values in array
then it will print \"I\'m in PrintFinal\"
it will print the indexes of two consecutive characters and
then the character.
public class Final2{
public static void main(String[] args) {
int []x=new int[21];
char []text={\'d\',\'g\',\'h\',\'h\',\'y\',\'w\'};
int y;
for(y=8;y<=14;y++)

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/3
x[y]=2*y-4;
System.out.println(\"I\'m in main\");
System.out.println(x[y]);
printFirst(x);
PrintChar(text);
PrintFinal(text);
}
public static void printFirst(int[] xx){
System.out.println(\"I\'m in the printFirst Method\");
int z;
for(z=8;z<=14;z++){
System.out.println(xx[z]);
}
}
public static void PrintChar(char[] xx){
System.out.println(\"I\'m in PrintChar\");
for(int i=0;i<xx.length;i++){
System.out.print(xx[i]+\" \");
}
System.out.println();
}
public static void PrintFinal(char[] xx){
System.out.println(\"I\'m in PrintFinal\");
for(int i=0;i<xx.length-1;i++){
if(xx[i]==xx[i+1]){

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/3

Sign up to view the full document!

lock_open Sign Up
Unformatted Attachment Preview
2. Trace the following part of codes step by ste, show eacly what will prat methods as requested public class Final2 t public static void main (String arg) int []x = new int[21] int y: for (y = 8; y Solution first it will print \"I\'m in main\". then it will print 0 because after completing the loop value of y will be 15 and x[15] =0. then it will print \"I\'m in PrintFirst\" and then values at index from 8 to 14 then it will print \"I\'m in PrinChar\" then it will print all the char values in array then it will print \"I\'m in PrintFinal\" it will print the indexes of two consecutive characters and then the character. public class Final2{ public static void main(String[] args) { int []x=new int[21]; char []text={\'d\',\'g\',\'h\',\'h\',\'y\',\'w\'}; int y; for(y=8;y ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.
Studypool
4.7
Indeed
4.5
Sitejabber
4.4