Java Programming How is the answer obtained? Is there a program where step by st
ID: 663447 • Letter: J
Question
Java Programming
How is the answer obtained? Is there a program where step by step method of how codes are executed is explained?
What is printed in the Output window when the code given below is compiled and run?
public static void main(String [ ] args) {
int [] x = {2, 1, 3};
int [] y = trouble(x);
for (int i=0; i<3; i++) System.out.print(x[i]);
for (int i=0; i<3; i++) System.out.print(y[i]);
}
public static int [] trouble(int [] a) {
int [] b = a;
for (int i=0; i<a.length; i++) b[i] = i*b[i];
return b;
}
Answer: 016016
Explanation / Answer
/*
Convert Integer object to String object
This example shows how a Integer object can be converted into String object.
*/
public class IntegerToStringExample {
public static void main(String[] args) {
Integer intObj = new Integer(10);
//use toString method of Integer class to conver Integer into String.
String str = intObj.toString();
System.out.println("Integer converted to String as " + str);
}
}
/*
Output of the program would be
Integer converted to String as 10
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.