> For the complete documentation index, see [llms.txt](https://educacion.gitbook.io/programacion/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://educacion.gitbook.io/programacion/exercicios-java/ud1-solucions/solucions-operador-ternario.md).

# Solucións operador ternario

1. Par ou impar

```java
import java.util.Scanner;

public class ParOuImpar {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        System.out.print("Introduce un número: ");
        int numero = scanner.nextInt();
        
        String resultado = (numero % 2 == 0) ? "O número é par" : "O número é impar";
        System.out.println(resultado);
        
        scanner.close();
    }
}
```

2. Múltiplo de 10

```java
import java.util.Scanner;

public class MultiploDe10 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        System.out.print("Introduce un número: ");
        int numero = scanner.nextInt();
        
        String resultado = (numero % 10 == 0) ? "É múltiplo de 10" : "Non é múltiplo de 10";
        System.out.println(resultado);
        
        scanner.close();
    }
}
```

3. Comparar dous números

```java
import java.util.Scanner;

public class CompararNumeros {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        System.out.print("Introduce o número A: ");
        int a = scanner.nextInt();
        
        System.out.print("Introduce o número B: ");
        int b = scanner.nextInt();
        
        String resultado = (a >= b) ? "O numero A é maior ou igual que o número B" : "O numero B é menor que o numero A";
        System.out.println(resultado);
        
        scanner.close();
    }
}
```

4. Positivo, negativo ou cero

```java
import java.util.Scanner;

public class PositivoCeroNegativo {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        System.out.print("Introduce un número: ");
        int numero = scanner.nextInt();
        
        String resultado = (numero >= 0) ? 
                          (numero == 0) ? "O número é cero" : "O número é positivo" 
                          : "O número é negativo";
        
        System.out.println(resultado);
        
        scanner.close();
    }
}
```


---

# 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://educacion.gitbook.io/programacion/exercicios-java/ud1-solucions/solucions-operador-ternario.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.
