Java Programming Competition I

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 Myrrh
M
Myrrh
Community Contributor
Quizzes Created: 1 | Total Attempts: 1,758
| Attempts: 1,758 | Questions: 50
Please wait...
Question 1 / 50
0 %
0/100
Score 0/100
1. What kind of programming language is Java?

Explanation

Java is classified as an object-oriented programming language because it is designed to organize and structure code around objects, which are instances of classes. It supports the principles of encapsulation, inheritance, and polymorphism, allowing developers to create modular and reusable code. Java also provides features like class hierarchies, interfaces, and dynamic binding, which are key components of object-oriented programming.

Submit
Please wait...
About This Quiz
Java Programming Competition I - Quiz

The 'JAVA Programming Competition I' quiz assesses knowledge in Java programming, covering data types, operators, and code execution outcomes. It is designed for learners to validate and enhance... see moretheir understanding of Java, preparing them for competitive programming challenges. see less

2. Consider the following line of Java code.    int x = 1+7*2; What will be the value of x at the end of execution of the line of code? 

Explanation

The value of x at the end of the execution of the line of code will be 15. This is because the multiplication operation has higher precedence than addition, so 7*2 is evaluated first, resulting in 14. Then, 1 is added to 14, giving a final value of 15 for x.

Submit
3. What is the output of the following code fragment:   int[] ar = {2, 4, 6, 8 }; System.out.println( ar[0] + " " + ar[1] );  

Explanation

The code fragment creates an array called "ar" with four elements: 2, 4, 6, and 8. The code then prints the value of the first element (ar[0]) followed by a space and the value of the second element (ar[1]). Therefore, the output of the code is "2 4".

Submit
4. Which one of the following is NOT a correct variable name? 

Explanation

not-available-via-ai

Submit
5. What is the output of the following program fragment?  for ( int j = 0;  j <  5; j++ ) {        System.out.print( j + " " ); } System.out.println( );  

Explanation

The program fragment uses a for loop to iterate from 0 to 4 (since j starts at 0 and the condition j

Submit
6. Does every Java variable use a data type? 

Explanation

Every Java variable must be declared along with its data type. This is because Java is a strongly typed language, which means that variables must have a specific type assigned to them before they can be used. This allows the compiler to allocate the appropriate amount of memory for the variable and perform type checking to ensure that the variable is used correctly. Without declaring the data type of a variable, the compiler would not know how to handle it, resulting in a compilation error.

Submit
7. What is the output of the following code fragment?  for ( int j = 10;  j >  5; j-- ) {      System.out.print( j + " " ); } System.out.println( );

Explanation

The code starts the loop with j = 10 and continues as long as j is greater than 5. In each iteration, it prints the value of j followed by a space. After the loop, it prints a new line. Therefore, the output of the code is "10 9 8 7 6".

Submit
8. What do you call a group of statements contained with an opening bracket and a closing bracket?

Explanation

A block statement refers to a group of statements enclosed within an opening bracket and a closing bracket. It is used to group multiple statements together, allowing them to be treated as a single unit. This can be helpful for organizing and controlling the flow of code execution.

Submit
9. What is a variable?

Explanation

A variable is a place to store information in a program. It is used to store and manipulate data during the execution of a program. Variables can hold different types of data such as numbers, text, or boolean values. They allow programmers to dynamically change and access data throughout the program, making it a fundamental concept in programming.

Submit
10. Another word for "looping" is:

Explanation

The word "looping" refers to the process of repeating a set of instructions or actions. Similarly, the word "iteration" also means the repetition of a process or set of instructions. Therefore, "iteration" is another word for "looping".

Submit
11. Pick the for loop which duplicates this while loop:  int x = 0; while ( x < 500 ) {   System.out.println( x );   x = x + 5; }  

Explanation

The correct answer is "for ( int x = 0; x System.out.println( x )". This for loop has the same initialization, condition, and increment as the while loop. It starts with x = 0, continues as long as x is less than 500, and increments x by 5 in each iteration. Additionally, it prints the value of x in each iteration, just like the while loop. Therefore, this for loop duplicates the behavior of the given while loop.

Submit
12. 49. What are the legal indexes for the array ar, given the following declaration:   int[] ar = {2, 4, 6, 8 }    

Explanation

The legal indexes for the array ar are 0, 1, 2, and 3. This is because the array has 4 elements and the indexes start from 0 and go up to 3.

Submit
13. The && operator works with which data types?  

Explanation

The && operator works with boolean data types. It is a logical operator that returns true if both operands are true, and false otherwise. It cannot be used with other data types such as int, long, or double.

Submit
14. What does this code print on the monitor?         int count = 7;                                          while ( count >= 4 )  {            System.out.print( count + " " );  count = count - 1;       } System.out.println(  );  

Explanation

The code initializes a variable called "count" with a value of 7. Then, it enters a while loop that continues as long as the value of "count" is greater than or equal to 4. Inside the loop, it prints the value of "count" followed by a space, and then decreases the value of "count" by 1. After the loop, it prints a new line character.

Therefore, the code will print the numbers 7, 6, 5, and 4 on the monitor, separated by spaces.

Submit
15. What condition should be used so that the code produce this output:         1 2 3 4 5 6 7 8  int count =  1;                                          while (  ___________ )  {             System.out.print( count + " " );                count = count + 1;       }  

Explanation

The condition "count

Submit
16. What is the output of the following code fragment?  for ( int j = 5;  j > -5; j-- )   System.out.print( j + " " );     System.out.println( );  

Explanation

The code starts with the variable j initialized to 5. It then enters a loop that continues as long as j is greater than -5. In each iteration of the loop, it prints the value of j followed by a space. After the loop, it prints a new line.

So, the output of the code will be: 5 4 3 2 1 0 -1 -2 -3 -4.

Submit
17. What must the initialization be so that the following fragment prints out the integers -3 -2 -1 ?  for ( _______; j < 0; j++    )   System.out.print( j + " " );

Explanation

The correct answer is "int j = -3" because the initialization of the variable "j" needs to be set to -3 in order for the condition "j

Submit
18.  What is the name for an application that changes a human-readable programming language into a machine-readable language?  

Explanation

A compiler is a software application that translates a human-readable programming language into a machine-readable language. It takes the source code written by a programmer and converts it into a binary code that can be executed by a computer. This process involves multiple stages, such as lexical analysis, syntax analysis, and code generation. Ultimately, a compiler enables the computer to understand and execute the instructions written by the programmer.

Submit
19. Which of the following statements are valid array declaration? (A) int number(); (B) float average[]; (C) double[] marks; (D) counter int[];  

Explanation

The valid array declarations are (B) float average[] and (C) double[] marks. In (B), an array named "average" of type float is declared. In (C), an array named "marks" of type double is declared using the array syntax. (A) int number() is not a valid array declaration as it uses parentheses instead of square brackets. (D) counter int[] is also not a valid array declaration as the type "counter" should come before the variable name.

Submit
20. What must the initialization be so that the following fragment prints out the integers -3 -2 -1 ?  for ( _______; j < 0; j++    )   System.out.print( j + " " );   System.out.println( );

Explanation

The correct answer is "int j = -3". This is because the for loop condition is "j

Submit
21. 48. Which of the following declares an array of int named img?

Explanation

The correct answer is "int[] img;". This declares an array of int named "img". The square brackets "[]" after the data type "int" indicate that it is an array. The variable name "img" follows the data type and is used to reference the array.

Submit
22. What must the change be so that the following fragment prints out the even integers 0 2 4 6 8 10?  for ( int j = 0; j <= 10; _______   )     System.out.print( j + " " ); System.out.println( );

Explanation

The change that needs to be made is to replace the blank with "j = j+2". This will increment the value of j by 2 in each iteration of the loop, resulting in the printing of the even integers 0 2 4 6 8 10.

Submit
23. 47. Which of the following statements does NOT define a String array called myArray that contains five elements?

Explanation

not-available-via-ai

Submit
24. What types of information are arrays best suited for?

Explanation

Arrays are best suited for storing and organizing lists of related information. Arrays allow for the efficient storage and retrieval of multiple values of the same data type, making them ideal for situations where a collection of data needs to be accessed and manipulated as a whole. Arrays provide a convenient way to keep track of and work with lists of items, such as a list of numbers, names, or any other type of data that needs to be grouped together.

Submit
25. What must the test be so that the following fragment prints out the integers -5 through and including 5?  for ( int j = -5;  ________ ; j++ ){   System.out.print( j + " " ); }   

Explanation

The test must be "j

Submit
26. When you compile a Java program, what are you doing?

Explanation

When you compile a Java program, you are converting it into a form that the computer can better understand. This process involves translating the human-readable code written in Java into machine-readable code, typically in the form of bytecode. The bytecode can then be executed by the Java Virtual Machine (JVM) on any platform, making Java programs highly portable. Compiling is an essential step in the software development process as it checks for syntax errors and produces an executable file that can be run on a computer.

Submit
27. What is the output of the following:                 int a = 0, b = 10;                a = --b ; System.out.println("a= " + a + "  b= " + b ); 

Explanation

The output of the given code is "a= 9 b=9". This is because the expression "--b" decrements the value of b by 1 before assigning it to a. So, a becomes 9 and b also becomes 9.

Submit
28. What is the meaning of variable++   ? 

Explanation

The expression variable++ is a post-increment operator. It adds one to the variable after its current value has been used. This means that if the variable has a value of 5, for example, the expression variable++ would use the current value of 5 and then increment the variable to 6.

Submit
29. Fill in the blank so that the following adds up the odd numbers from 1 to 99  int sum = 0; for ( int num = 1; num <=99; __________ )   sum += num;        System.out.println( sum );     

Explanation

The correct answer is "num+=2". This is because "num+=2" is equivalent to "num = num + 2", which means that the variable "num" will increase by 2 in each iteration of the loop. By starting at 1 and increasing by 2, the loop will only consider odd numbers. Therefore, the sum variable will add up all the odd numbers from 1 to 99.

Submit
30.  What is the output of the following code fragment?  int count = 0; for ( ;  count < 9; ++count )          System.out.print( count + " " );

Explanation

The code fragment initializes a variable "count" to 0. It then enters a for loop that continues as long as "count" is less than 9. In each iteration of the loop, "count" is incremented by 1 and the value of "count" is printed. This process continues until "count" reaches 9, at which point the loop exits. Therefore, the output of the code fragment will be the numbers 0 through 8, separated by spaces.

Submit
31. What must the test be so that the following fragment prints out the integers 5 through and including 15?  for ( int j = 5;  ________ ; j++ ) {     System.out.print( j + " " ); }     

Explanation

The test in the blank must be "j

Submit
32. What must the test be so that the following fragment prints out the integers from 5 through 15?  for ( int j = 5;  ________ ; j++ ){     System.out.print( j + " " ); }System.out.println( );

Explanation

The test must be "j <= 15" in order for the fragment to print out the integers from 5 through 15. This is because the loop will continue as long as the condition "j <= 15" is true, and it will stop when j becomes greater than 15.

Submit
33. What does the following program output to the monitor:                   int value = 0, count = 1;                  value = count++ ; System.out.println("value: "+ value  + "count: " + count );   

Explanation

The program first assigns the value of count to value and then increments the value of count by 1. Therefore, the output will be "value: 1 count: 2".

Submit
34. Which of the answers does the same thing as the following: value += sum++ ;  

Explanation

The given expression "value += sum++" is equivalent to "value = value + sum; sum = sum + 1;". The expression "value += sum++" adds the value of "sum" to the value of "value", and then increments the value of "sum" by 1. This is exactly what is happening in the alternative answer "value = value + sum; sum = sum + 1;".

Submit
35. What does this code print on the monitor?        int count =  1;                                          while ( count < 5 )  {             System.out.print( count + " " );       } System.out.println(  );

Explanation

The code initializes a variable "count" with the value 1. Then, it enters a while loop that will continue as long as "count" is less than 5. Inside the loop, it prints the value of "count" followed by a space. Since the loop does not modify the value of "count", it will always be 1. Therefore, the code will keep printing "1 " indefinitely until it is terminated.

Submit
36. What must the change be so that the following fragment prints out the even integers 0 2 4 6 8 10?  for ( int j = 0; j <= 10; _______   )   System.out.print( j + " " );

Explanation

The correct answer is "j = j+2". This change will increment the value of j by 2 in each iteration of the loop, starting from 0. As a result, the loop will print out the even integers 0, 2, 4, 6, 8, and 10.

Submit
37. Examine the following code fragment:        int j = 1;       while (  j < 10  ) {                 System.out.println( j + " " );            j = j + j%3;       } What is output?  

Explanation

The code fragment starts with initializing the variable j to 1. Then, it enters a while loop with the condition that j is less than 10. Inside the loop, it prints the value of j followed by a space. After that, it updates the value of j by adding the remainder of j divided by 3 to itself. This process continues until j becomes greater than or equal to 10.

Based on this logic, the output will be 1 2 4 5 7 8.

Submit
38. Pick the for loop which duplicates this while loop:  double x = 0.0; while ( x < 100.0 ) {   System.out.println( x );           x += 0.1;  }

Explanation

The correct answer is "double x;

for ( x = 0.0; x System.out.println( x );"

This for loop duplicates the while loop because it initializes a variable x as a double with a value of 0.0. It then sets the condition for the loop to continue as long as x is less than 100.0. After each iteration, it increments x by 0.1. Finally, it prints the value of x. This is exactly what the while loop does.

Submit
39. What does the following statement do?     String[] widget;

Explanation

The statement "String[] widget;" declares a variable named widget which is of type String array. It indicates that the variable widget can potentially hold a reference to an array of references to String objects. However, at the moment of declaration, the variable is initialized to null, meaning it does not currently refer to any object or array.

Submit
40. Given the declaration   String[] names = new String[10] ; Which of the following statements puts a reference to the String "Hello" in the last slot of the array?  

Explanation

The correct answer is names[9] = "Hello"; because arrays in Java are zero-indexed, meaning that the first element is at index 0 and the last element is at index length-1. Therefore, to put a reference to "Hello" in the last slot of the array, we need to access index 9.

Submit
41. What does the following statement do?   String[] names = new String[10] ;  

Explanation

The given statement declares the variable "names" to be a reference to an array of String references. It also constructs an array object that can hold references to 10 String objects. This means that the "names" array can store up to 10 String values.

Submit
42. What is the difference between   String rats; and   String[] rats;                 ?    

Explanation

The first statement "String rats;" declares "rats" to be a reference variable that can hold a reference to a single String object. On the other hand, the second statement "String[] rats;" declares "rats" to be a reference variable that can hold a reference to an array of String references. This means that the second statement allows "rats" to refer to multiple String objects, while the first statement only allows it to refer to a single String object.

Submit
43. Fill the blank so that the following fragment prints out 0.2, 0.4, 0.6, 0.8, 1.0,  for ( int j = 2; j <= 10; j+=2   )   System.out.print( __________ + ", " );  

Explanation

The correct answer is "j/10.0" because it divides the value of j by 10.0, which is a float, resulting in a decimal value. This will print out the desired sequence of 0.2, 0.4, 0.6, 0.8, and 1.0.

Submit
44. What does the following statement do?   int[] values = new int[10] ;  

Explanation

The given statement declares the variable "values" to be a reference to an array object. It also constructs an array object with a size of 10, where each element is initialized to zero.

Submit
45. The Java expression: !((b != 0) || (c <= 5)) is equivalent to: 

Explanation

The given Java expression is using the logical NOT operator (!) to negate the result of the logical OR operator (||). This means that the expression will be true only if both conditions inside the parentheses are false.

In the first option, !(b = 0) is incorrect because it is using the assignment operator (=) instead of the comparison operator (==).

In the second option, (b==0) && (c >5) is correct because it checks if b is equal to 0 and c is greater than 5.

The third and fourth options are incomplete and do not provide a valid expression.

Submit
46. 46. Consider the following code int number[] = new int[5]; After execution of this statement, which of the following are true?  (A) number[0] is undefined (B) number[5] is undefined (C) number[4] is null (D) number[2] is 0 (E) number.length() is 5  

Explanation

After executing the statement "int number[] = new int[5];", the following statements are true:

(B) number[5] is undefined: This is true because the array "number" has a size of 5, but the indexes of an array start from 0. Therefore, the index number[5] is out of bounds and undefined.

(D) number[2] is 0: This is true because when an array of integers is created, all the elements are initialized to their default value, which is 0 for integers. Therefore, number[2] will be 0.

(E) number.length() is 5: This is true because the length property of an array returns the number of elements in the array, which in this case is 5.

Submit
47. What is the range of an int data type in Java?

Explanation

The correct answer is -2^31 to 2^31 - 1. In Java, the int data type is a 32-bit signed two's complement integer. The range of values that can be stored in an int variable is from -2^31 to 2^31 - 1. The lower limit is -2^31 because one bit is used to represent the sign of the number. The upper limit is 2^31 - 1 because the remaining 31 bits are used to represent the magnitude of the number.

Submit
48. What is the result of evaluating the following expression?     (1/2 + 3.5) * 2.0  

Explanation

The expression (1/2 + 3.5) * 2.0 can be evaluated as follows: 1/2 = 0.5 0.5 + 3.5 = 4.0 4.0 * 2.0 = 8.0 Therefore, the correct answer is 8.0.

Submit
49.  For the code below: Which are printed to standard output? int m = 0; while( m++ < 2 ) System.out.print(m);  

Explanation

The code initializes a variable "m" to 0 and then enters a while loop. In each iteration of the loop, the value of "m" is incremented by 1 and then printed to the standard output. The loop continues until "m" becomes 2. Therefore, the numbers 1 and 2 are printed to the standard output.

Submit
50. What is the process of fixing errors called?

Explanation

not-available-via-ai

Submit
View My Results

Quiz Review Timeline (Updated): Jul 4, 2024 +

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

  • Current Version
  • Jul 04, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Dec 08, 2011
    Quiz Created by
    Myrrh
Cancel
  • All
    All (50)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What kind of programming language is Java?
Consider the following line of Java code.    int x = 1+7*2;...
What is the output of the following code fragment:...
Which one of the following is NOT a correct variable name? 
What is the output of the following program fragment? ...
Does every Java variable use a data type? 
What is the output of the following code fragment? ...
What do you call a group of statements contained with an opening...
What is a variable?
Another word for "looping" is:
Pick the for loop which duplicates this while loop: ...
49. What are the legal indexes for the array ar, given the following...
The && operator works with which data types?  
What does this code print on the monitor? ...
What condition should be used so that the code produce this output:...
What is the output of the following code fragment? ...
What must the initialization be so that the following fragment prints...
 What is the name for an application that changes a...
Which of the following statements are valid array declaration?...
What must the initialization be so that the following fragment prints...
48. Which of the following declares an array of int named img?
What must the change be so that the following fragment prints out the...
47. Which of the following statements does NOT define a String array...
What types of information are arrays best suited for?
What must the test be so that the following fragment prints out the...
When you compile a Java program, what are you doing?
What is the output of the following: ...
What is the meaning of variable++   ? 
Fill in the blank so that the following adds up the odd numbers from 1...
 What is the output of the following code fragment? ...
What must the test be so that the following fragment prints out the...
What must the test be so that the following fragment prints out the...
What does the following program output to the monitor: ...
Which of the answers does the same thing as the following: value +=...
What does this code print on the monitor?...
What must the change be so that the following fragment prints out the...
Examine the following code fragment: ...
Pick the for loop which duplicates this while loop: ...
What does the following statement do?     String[] widget;
Given the declaration...
What does the following statement do?...
What is the difference between...
Fill the blank so that the following fragment prints out 0.2, 0.4,...
What does the following statement do?...
The Java expression: !((b != 0) || (c <= 5)) is equivalent...
46. Consider the following code...
What is the range of an int data type in Java?
What is the result of evaluating the following expression?  ...
 For the code below: Which are printed to standard output?...
What is the process of fixing errors called?
Alert!

Advertisement