2
28/10/2024 7:26 pm
Inicio del tema
Write a program that takes as input two integers N and M, and randomizes the numbers between them. Note that M may be smaller than or equal to N:
1 respuesta
2
28/10/2024 7:27 pm
Here is the solution for this taks, mate:
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Pr_7_RandomizeNumbersFromNToM { public static void main(String[] args) { Scanner console = new Scanner(System.in); int n = console.nextInt(); int m = console.nextInt(); int maxNumber = 0; int minNumber = 0; if (n > m) { maxNumber = n; minNumber = m; } else if (n < m) { maxNumber = m; minNumber = n; } else { System.out.println(n); } List<Integer> numbers = new ArrayList<>(); for (int i = minNumber; i <= maxNumber; i++) { numbers.add(i); Collections.shuffle(numbers); } for (int item : numbers) { System.out.println(item); } } }
Por favor Iniciar Sesión o Registro para responder a este debate