Advertisement
joseleonweb

Untitled

Aug 23rd, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CercarDivisor {
  4.   public static void main (String[] args) {
  5.     Scanner lector = new Scanner(System.in);
  6.  
  7.     System.out.print("Quin nombre vols analitzar? ");
  8.     int valor = lector.nextInt();
  9.     lector.nextLine();
  10.  
  11.     boolean trobat = false;
  12.     int divisor = valor - 1;
  13.  
  14.     while ((!trobat)&&(divisor > 1)) {
  15.       if ((valor % divisor) == 0) {
  16.         trobat = true;
  17.       } else {
  18.         divisor--;
  19.       }
  20.     }
  21.     if (divisor == 1) {
  22.       System.out.println("No s'ha trobat cap divisor.");
  23.     } else {
  24.       System.out.println("El divisor és " + divisor + ".");
  25.     }
  26.   }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement