> 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/ud2-solucions/bucles/exercicios-introductorios.md).

# Exercicios introductorios

1. Intenta **SEN UTILIZAR O IDE** determinar cal e a saida dos seguintes códigos:
   1. 1 2 3 4 5 6 7 8 9
   2. 1 3 5 7 9
   3. Bucle infinito
   4. 10 9 8 7 6 5 4 3 2 1
   5. 20 21 22 23 24 25 26 27 28 29 30
   6. 23 24 25 26 27
   7. 30 29 28 27 26 25 24 23 22 21 20
   8. Bucle infinito
   9. 10
   10. 10 14 18
2. Mostrar por pantalla a frase "Probando os bucles" n veces, sendo n un número que introduce un usuario por pantalla. Utilizar un bucle FOR

```java
import java.util.Scanner;

public class Exercicio1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        System.out.print("Introduce o número de veces (n): ");
        int n = scanner.nextInt();
        
        for (int i = 0; i < n; i++) {
            System.out.println("Probando os bucles");
        }
        
        scanner.close();
    }
}
```

3. Escribe un programa mostre por pantalla os n primeiros números naturales, sendo n un valor que introduce o usuario por pantalla. Utilizar un bucle WHILE

```java
import java.util.Scanner;

public class Exercicio2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        System.out.print("Introduce o valor de n: ");
        int n = scanner.nextInt();
        
        int i = 1;
        while (i <= n) {
            System.out.println(i);
            i++;
        }
        
        scanner.close();
    }
}
```

4. Escribe un programa que pida números o usuario por pantalla e escriba "O número introducido é N" mentras que o numero introducido non sexa múltiplo de 4. Se o numero é múltiplo de 4 mostrara a mensaxe por pantalla e finalizará a execución.

```java
import java.util.Scanner;

public class MathJava {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int numero;

        do {
            System.out.print("Introduce un número: ");
            numero = scanner.nextInt();
            System.out.println("O número introducido é " + numero);

        } while (numero % 4 != 0);
        System.out.println("Finalizando programa.");
        scanner.close();
    }
}

```

5. Conta atras

```java
public class ParesSinModulo {
    public static void main(String[] args) {
        System.out.println("Números pares entre 100 e 1:");
        
        // Comezamos en 100 (par) e decrementamos de 2 en 2
        for (int i = 100; i >= 2; i -= 2) {
            System.out.println(i);
        }
    }
}
```

6. Tabla de multiplicar inversa

```java
public class TaboaMultiplicarInversa {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        System.out.print("De que número queres a taboa inversa? ");
        int numero = scanner.nextInt();
        
        System.out.println("Taboa de multiplicar inversa do " + numero + ":");
        
        // De 10 a 1 con incremento negativo
        for (int i = 10; i >= 1; i--) {
            System.out.println(numero + " x " + i + " = " + (numero * i));
        }
        
        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/ud2-solucions/bucles/exercicios-introductorios.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.
