• Lenguaje

    Java usando Scanner

  • Descripción

    Determinar si un valor N (cualquiera), es divisor común de otros dos valores X y Y (que se ingresan por teclado).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.Scanner;

public class DivisorComunDeDosValores {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n, x, y;
        System.out.print("Ingresa el valor de n: ");
        n = in.nextInt();
        in.nextLine();
        System.out.print("Ingresa el valor de x: ");
        x = in.nextInt();
        in.nextLine();
        System.out.print("Ingresa el valor de y: ");
        y = in.nextInt();
        in.nextLine();
        if(x%n==0&&y%n==0)
            System.out.println("N s\u00ED es divisor com\u00FAn de X y Y.");
        else
            System.out.println("N no es divisor com\u00FAn de X y Y.");
    }

}