• Lenguaje

    Java usando Scanner

  • Descripción

    Hallar el cociente y el residuo (resto) de dos números.

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

public class CocienteYResiduoDeDosNumeros {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a, b, cociente, residuo;
        System.out.print("Ingresa el valor de a: ");
        a = in.nextInt();
        in.nextLine();
        System.out.print("Ingresa el valor de b: ");
        b = in.nextInt();
        in.nextLine();
        if(b!=0)
        {
            cociente=a/b;
            residuo=a%b;
        }
        else
        {
            cociente=0;
            residuo=0;
            System.out.println("Intederminaci\u00F3n");
        }
        System.out.println("Valor de cociente: " + cociente);
        System.out.println("Valor de residuo: " + residuo);
    }

}