Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CercarDivisor {
- public static void main (String[] args) {
- Scanner lector = new Scanner(System.in);
- System.out.print("Quin nombre vols analitzar? ");
- int valor = lector.nextInt();
- lector.nextLine();
- boolean trobat = false;
- int divisor = valor - 1;
- while ((!trobat)&&(divisor > 1)) {
- if ((valor % divisor) == 0) {
- trobat = true;
- } else {
- divisor--;
- }
- }
- if (divisor == 1) {
- System.out.println("No s'ha trobat cap divisor.");
- } else {
- System.out.println("El divisor Ês " + divisor + ".");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment