output based question in java send me practice questions
Answers
Answer:
what were the similarities between colonial management of the forest in Java and bastar
Answer:
hey here is your answer
1) What will be the output of following program ?
1
2
3
4
5
public class Prg {
public static void main(String args[]){
System.out.print('A' + 'B');
}
}
AB
195
131
Error
Answer
Correct Answer: 3
131
Here, ‘A’ and ‘B’ are not strings they are characters. ‘A’ and ‘B’ will not concatenate. The Unicode of the ‘A’ and ‘B’ will add. The Unicode of ‘A’ is 65 and ‘B’ is 66. Hence Output will be 131.
2) What will be the output of following program ?
1
2
3
4
5
public class Prg {
public static void main(String args[]){
System.out.print("A" + "B" + 'A');
}
}
ABA
AB65
Error
AB
Answer
Correct Answer: 1
ABA
If you try to concatenate any type of data like integer, character, float with string value, the result will be a string. So 'A' will be concatenated with "AB" and answer will be "ABA".
3) What will be the output of following program?
1
2
3
4
5
public class Prg {
public static void main(String args[]){
System.out.print(20+ 1.34f + "A" + "B");
}
}
201.34AB
201.34fAB
21.34AB
Error
Answer
Correct Answer: 3
21.34AB
20 and 1.34f will be added and then 21.34 will be concatenated with “A” and “B”, hence output will be 21.34AB.
4) What will be the output of following program?
1
2
3
4
5
6
public class Prg {
public static void main(String[] args) {
char [] str={'i','n','c','l','u','d','e','h','e','l','p'};
System.out.println(str.toString());
}
}
includehelp
Error
[C@19e0bfd (Memory Address)
NULL
Answer
Correct Answer: 3
[C@19e0bfd (Meory Address)
str is a character array, if you try to print str.toString() it will not converted to string because str is an object of character array that will print an address in string format.
5) What will be the output of following program?
1
2
3
4
5
6
public class prg {
public static void main(String[] args) {
System.out.print("Hello");
System.out.println("Guys!");
}
}
HelloGuys!
Hello Guys!
Hello
Guys!
Compile with a Warning
Answer
Correct Answer: 1
HelloGuys!
System.out.print() does not print new line after printing string, while System.out.println(); prints new line after printing string. Hence output will be HelloGuys! and then new line.