> For the complete documentation index, see [llms.txt](https://vives.gitbook.io/oop-with-java/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vives.gitbook.io/oop-with-java/making-decisions/challenges.md).

# Challenges

This chapter may require you to request input from the user. This can be achieved by using the code below:

```java
public static void main(String[] args) {
    Scanner console = new Scanner(System.in);

    System.out.print("Please enter a number: ");
    int number = console.nextInt();
    System.out.println("You entered the value " + number);
}
```

This code snippet requests a number from the user and stores it in the variable `number`. It then outputs it back to the terminal. Feel free to change the name of the variable to suit your application.

Do note that if you input anything else than a integral number, the application will crash. Don't worry about it for the moment. This will be fixed later on in the course.

## Boolean Expressions

Fill in the table below with the correct outcomes of the boolean expressions.

| A       | B       | C       | Expression                    | Outcome of Expression |
| ------- | ------- | ------- | ----------------------------- | --------------------- |
| `false` | `false` | `false` | `A && B`                      |                       |
| `true`  | `true`  | `false` | `(!A) && B`                   |                       |
| `true`  | `true`  | `true`  | `(!A) && (!B) && C`           |                       |
| `false` | `false` | `false` | `A \|\| B`                    |                       |
| `false` | `true`  | `false` | `!(B && C)`                   |                       |
| `false` | `true`  | `false` | `C \|\| (!C)`                 |                       |
| `false` | `false` | `false` | `!(B \|\| C)`                 |                       |
| `false` | `false` | `true`  | `!((!B) \|\| (!C))`           |                       |
| `false` | `true`  | `true`  | `A && (!A)`                   |                       |
| `true`  | `true`  | `false` | `((!A) \|\| (!B) && C) && !C` |                       |

## Check if negative

Start with the code snippet provided at the start of this challenge chapter to request a number from the user.

Now output a message based on the value of number:

* if `number` is negative, output the message: "The number is negative"
* if `number` is 0, output the message: "The number is zero"
* if `number` is positive, output the message: "The number is positive"

Run the application multiple times with different input to test your app.

## Square

Create an application that requests the length of a side of a square. Calculate the circumference and the area. Output both to the user.

For example:

```
Please enter side of square in meters: 5

The circumference is: 20 meters
The area is: 25 square meters
```

## Minimum and Maximum

Create an application that requests two numbers from the user. Determine which number of the two is the biggest and then output your findings to the user.

For example:

```
Please enter first number: 15
Please enter second number: 88

The biggest number is: 88
The smallest number is: 15
```

## Square roots

Search the Internet on how to make the square root of an Integer in Java.

Now let the user enter an integral value and calculate the square roots of that given number. A positive integral value has two square roots, the positive square root and the negative. So the square roots of `9` are `3` and `-3`.

Make sure to put a check in place for negative values as these cannot be processed and will crash your application. However, the square root of the negative number is the square root of the same positive value but in its complex form. For example: the square roots of `-9` are `3i` and `-3i`.

Example output:

```
Welcome to my Square Root application.

Enter an integral value to get the roots of it.

Please enter a value: 16

The square roots are 4 and -4

Thanks for using my app. Goodbye.
```

Or when entering a negative value:

```
Welcome to my Square Root application.

Enter an integral value to get the roots of it.

Please enter a value: -16

The square roots are 4i and -4i

Thanks for using my app. Goodbye.
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vives.gitbook.io/oop-with-java/making-decisions/challenges.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
