Category: Last published

Java puzzle 21: Using inheritance

If this code is compiled and run, it writes 5, 6 to the standard output. Write only one statement at line 8 of the class MySub. As a result of that the program writes 2, 7 to the standard output. What is that statement? Java puzzle 21: Using inheritance Level: Normal Author: Sar Maroof Answer […]

Java puzzle 20: Classes and constructors

If this code is compiled and run, it writes nullx2 to the standard output. Write only one statement at line 8. As a result of your statement the program writes xx3 to the standard output. What is that statement? Java puzzle 20: Classes and constructors Level: Normal Author: Sar Maroof Answer explanation The statement should […]

Java quiz 20: Convert from a class to interfaces

In this quiz InterfaceA extends InterfaceB. The class MyClass implements InterfaceA. The question is whether it is allowed to convert from MyClass to both interfaces and what the consequences would be. Java quiz 20: Convert from a class to interfaces Level: Normal What is written to the standard output as the result of executing the […]

Java assignment 08: Examen results

The output of this code is nothing. We pass the variable grade to the method. The method should do the following! If the number 10 is passed to the method, the ouput is Excellent. If the number 9 is passed to the method, the ouput is Very good. If the numbers 8, 7 and 6 […]

Java assignment 07: Find the leap years

The output of this code is nothing. if the code is compiled and run, the method leapYear should write all the leap years from 2021 till 2053 to the standard output. Write the code inside the method leapYear to achieve that. Note: A leap year is divisible by 4 with no remainder. Java assignment 07: […]

Java assignment 06: Find the sum of integers

The output of this code is nothing. The method writeSum should write the sum of three integers, namely i, i2, i3 to the standard output. If your method works correctly, the output of the program will be 23 + 17 + 3 = 43. Test your method by passing the following set of parameters to […]

Java assignment 05: Write the largest integer

Write the body of the method getLargest. The method writes the largest number out of three integers. If two or more equal largest integers are passed to the method, the output of the program should be “Enter unique numbers!”. If your method works correctly, the output of the following program will be 7. Test your […]

Java puzzle 19: Overloading methods

If this code is compiled and run, it writes null3 to the standard output. Write only one statement at line 9. As a result of that statement the output of the program becomes x5. What is that statement? Java puzzle 19: Overloading methods Level: Normal Author: Sar Maroof Answer explanation To solve this puzzle we […]

Java quiz 19: Conditional statements

Let’s start with today’s simple quiz for beginners. Java quiz 19: Conditional statements Level: Easy What is written to the standard output as the result of executing the following code? Author: Sar Maroof Answer explanation The statement if(y > (x + 4) || (y – 3) == x) returns false, because y is not greater […]

Sar Maroof’s online activities

Here below are my pages as Java author! Website Author’s page Amazon English: Author’s page Brinkman publisher Dutch version: Java quizmaster for beginners Brinkman publisher Dutch version: Build a Java application Here below are the websites on which I post Java related exercises, quizzes and puzzles. Website Activities Members Dzone American website Advanced Java quizzes […]

Java quiz 18: A while loop & conditional statements

Here we have a combination of a while loop and a conditional statement. Java quiz 18: A while loop and conditional statements Level: Normal What is written to the standard output as the result of executing the following code? Author: Sar Maroof Answer explanation The boolean variable isActive is not initialized. Therefore its value is […]

Java puzzle 18: Classes and objects

If this program is compiled and run, it writes pp9 to the standard output. Write only one statement at line 27. As a result of that statement the output of this code becomes 456. What is that statement? Java puzzle 18: Classes and objects Level: Hard Author: Sar Maroof Answer explanation We need to reassign […]

Java puzzle 17: Classes and objects

The output of this code is 2y2. Add only one statement at line 20. As a result of your statement, the output of the program becomes 9×5. What is that statement? Java puzzle 17: Classes and objects Level: Hard Author: Sar Maroof Answer explanation The statement should reassign the variable i of the object mc. […]

Java puzzle 16: Conditional statements within a loop

Here is the puzzle of today, which demonstrates a conditional statement within a loop. Java puzzle 16: Conditional statements within a loop Level: Normal What is the output of this program and why? Author: Sar Maroof Answer explanation The loop is repeated 4 times, because the initial value of the variable i is 0 and […]

Java quiz 17: Working with ArrayLists

ArrayList is used in Java to collect data. If you are not familiar with ArrayLists, you can read this article about ArrayList. Java quiz 17: Working with ArrayLists Level: Hard What is written to the standard output as the result of executing the following code? Author: Sar Maroof Answer explanation The statement ml1.list2 = ml1.method(ml1.list); […]

Java puzzle 15: Objects and methods

If this program is compiled and run, it writes 2x to the standard output. Write only one statement on line 14. As a result of your statement the program should write 7xy to the standard output. What is that statement? Java puzzle 15: Objects and methods Level: Normal Author: Sar Maroof Answer explanation The program […]

Java quiz 16: Ternary operator

Here is an example that shows how the ternary operator works in Java. Java quiz 16: Ternary operator Level: easy What is the output of this code? Author: Sar Maroof Answer explanation The statement int y = (x < 3) ? 4 : 8; means The statement if(x < 3) returns false, because x is […]

Why quizzes are more popular than assignments?

I post Java quizzes, puzzles and assignments on 6 Java pages and groups on Facebook, DZone, Twitter and this website, see the links below. It caught my attention that the quizzes attract thousands of readers and even more, but the Java puzzles and the assignments are reached by less people. I haven’t a clear explanation […]

Are you ready to build a Java application?

I have posted the last 6 weeks more than 30 Java quizzes, puzzles and assignments regards different Java topics. The exercises were offered in three levels namely, easy, normal and hard. If you understood all the easy and the normal level exercises properly, you can start building a Java application using my new book Build a […]

Java quiz 15: Loop within loop

For many of the projects on which I worked, I needed to use loops within loops. In the beginning seems very hard, but if you understand the process you become gradually familiar with it. Java quiz 15: Loop within loop Level: Hard What is the output of this code? Author: Sar Maroof Answer explanation If […]

Java puzzle 13: Invoking methods

In this Java puzzle the method myMethod is invoked, which returns an integer variable. Two integer parameters are passed to the method. Java puzzle 13: Invoking a method Level: Easy What is the output of this program and why? Author: Sar Maroof Answer explanation The parameters 3 and 5 are passed to the method myMethod. […]

Java puzzle 12: Passing parameters to constructors

In this Java puzzle we pass a parameter to a constructor. I congratulate you if you can solve this puzzle! Java puzzle 12: Passing a parameter to a constructor Level: Hard What is the output of this program and why? Author: Sar Maroof Answer explanation The statement new MyClass().method(3); instantiates an object from the class […]

Java quiz 14: Comparing strings

As a Java programmer you need very often to work with strings. Here is a simple quiz that shows the way Java handles strings. Java quiz 14: Comparing strings Level: Normal What happens when the following program is compiled and run?   Author: Sar Maroof Answer explanation The first conditional statement if (str1 == str2) […]

Java puzzle 11: Operators

The combination of operators and conditional statements appear in almost every program. Every Java programmer should master all types of conditional statements. Therefore, I focus to offer that in different ways in my puzzles and quizzes. Please, always check out the explanation of the answer if you have doubts. Java puzzle 11: Operators and conditional […]

Java puzzle 10: Switch statement

Java puzzle 10: A switch statement Level: Normal What is the output of this program and why? Author: Sar Maroof Answer explanation Answer explanation The initial value of x is 2. So, case 1 doesn’t match the value of x. The statement x++; under case 2 is executed and the value of x is incremented […]

Java puzzle 09: Demonstrating a for loop

The process of loops is one of the most difficult concept for beginner programmers. To master loops you need to practice and parctice again. Therefore, I demonstrate many loops for beginners to solve. This loop is a for loop, which is often used in almost every Java program. You might need a pen and a […]

Sarmaroof © 2017