TESTED QUESTIONS WITH CORRECT
SOLUTIONS!!
What will this code segment output?
System.out.println("Hello");
System.out.println("World");
A.
Hello
World
B. HelloWorld
C. Hello World
D.
Hello
World correct answers A.
Hello
World
Which code segment will print "Hello Karel" to the screen in Java?
A. System.out.printLine("Hello Karel");
B. print "Hello Karel";
C. System.out.println("Hello Karel");
D. System.println("Hello Karel"); correct answers C. System.out.println("Hello Karel");
What will this code segment output?
public class Printing
{
public static void main(String[] args)
{
System.out.println("*****");
System.out.println("****");
System.out.println("***");
System.out.println("**");
System.out.println("*");
}
}
A.
This won't print anything.
B.
*
**
***
, ****
*****
C.
It will only print the first line as ***** since only one print statement can be used.
D.
*****
****
***
**
* correct answers D.
*****
****
***
**
*
What is the correct syntax for writing the main method in Java?
A.
public void main( )
{
}
B.
public static void main( )
{
}
C.
public static void main(String[ ] args)
{
}
D.
public static void String(main)
{
} correct answers C.
public static void main(String[ ] args)
{
}
Which of the following is a proper way to declare and initialize a variable in Java?
A. myInteger = 100;
B. char = 'a';
C. int myNumber = 10;
D. "Variable" correct answers C. int myNumber = 10;
Consider the following code snippet.