Java CIS 109 Test 1

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Xenonii
X
Xenonii
Community Contributor
Quizzes Created: 4 | Total Attempts: 992
| Attempts: 305 | Questions: 12
Please wait...
Question 1 / 12
0 %
0/100
Score 0/100
1. What will this output?
int i = 10;
int j = 20;
System.out.println("The result of "+j+" division by 2 is "+i+".");

Explanation

The given code will output "The result of 20 division by 2 is 10." This is because the code is using the variables `i` and `j` in the `System.out.println()` statement. The value of `j` is 20 and the value of `i` is 10. So when the code is executed, it will print the string "The result of 20 division by 2 is 10."

Submit
Please wait...
About This Quiz
Java Quizzes & Trivia

You will be tested on java constructs such as loops, if conditions, methods etc

Personalize your quiz and earn a certificate with your name on it!
2. What will this output?
System.out.println(4 + 5 * 2);

Explanation

The * operator has a higher precedence than the plus operator

Submit
3. What is the return types of the following body of a method
{
   double d = 10;
   return 3 * d;
}

Explanation

The return type of the given method is "double" because the method is declared to return a value of type "double" and the expression "3 * d" evaluates to a double value.

Submit
4. Which is the correct boolean expression which gives the following meaning:
The value of x is greater than 1000 and x is smaller or equal to 2000

Explanation

The correct boolean expression is "x > 1000 && x

Submit
5. What will be the output of the following program
class A
{
   public static void main(String[] args)
   {
      System.out.println(getWelcomeMessage());
   }

   static String getWelcomeMessage()
   {
      return "Welcome!!!";
   }
}

Explanation

The program will output "Welcome!!!" because the main method calls the getWelcomeMessage() method, which returns the string "Welcome!!!" and then prints it using the System.out.println() method.

Submit
6. What will the following output on the screen?
for (int i = 0; i < 5; i++)
{
   System.out.print("*");
}

Explanation

It will only output 5 stars one after the other on the same line, because print is being used and not println. The counter i starts from 0, then it will execute the body of the for loop while i is less than 5. It would have output 6 stars if it was i

Submit
7. What is the return types of the following body of a method
{
   int i = 10;
   return 3 * i;
}

Explanation

The return type of the given method body is "int" because the method is declared to return an integer value. The body of the method initializes an integer variable "i" with a value of 10 and then returns the result of multiplying 3 with "i", which is an integer value. Therefore, the correct answer is "int".

Submit
8. Will the following compile?
int i = 0;
for (    ; i < 5 ;   )
{
   System.out.println(i);
   i++;
}

Explanation

The for loops consists of
for (; ; )
All of these are optional and you can leave any of them out. Try experimenting it on BlueJ.

Submit
9. What is the return types of the following body of a method
{
   return "test "+123;
}

Explanation

The return type of the given method is String because the body of the method is returning a string value "test "+123. The return statement is used to return a value from a method, and in this case, the value being returned is a string.

Submit
10. Will this compile?
class A
{
    System.out.println(20 * 10);
}

Explanation

No it won't because such a statement should be within some method, e.g. the main method.

Submit
11. What will this output?
System.out.println(5/2);

Explanation

Since you are dividing two integers, the result is also an integer. It simply doesn't output the decimal part of the result. If you wanted to show a decimal number, one of them needs to be a double. E.g. 3/2.0

Submit
12. Will this compile?
class B
{
   public static void main(String[] args)
   {
      Scanner sc = new Scanner(System.in);
   }
}

Explanation

No, because you need to import java.util.Scanner

Submit
View My Results

Quiz Review Timeline (Updated): Mar 18, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 18, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Nov 13, 2008
    Quiz Created by
    Xenonii
Cancel
  • All
    All (12)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What will this output?int i = 10;int j = 20;System.out.println("The...
What will this output?System.out.println(4 + 5 * 2);
What is the return types of the following body of a method ...
Which is the correct boolean expression which gives the following...
What will be the output of the following programclass A{  ...
What will the following output on the screen?for (int i = 0; i < 5;...
What is the return types of the following body of a...
Will the following compile?int i = 0;for (    ; i <...
What is the return types of the following body of a method ...
Will this compile?class A{    System.out.println(20 *...
What will this output?System.out.println(5/2);
Will this compile?class B{   public static void...
Alert!

Advertisement