• Lenguaje

    Java usando Scanner

  • Descripción

    Dado un número natural de 5 cifras, determine la suma y el producto de las cifras del número.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import java.util.Scanner;

public class ProductoDe5Cifras {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int producto, un_numero;
        System.out.print("Ingresa el valor de un numero: ");
        un_numero = in.nextInt();
        in.nextLine();
        producto=((un_numero%100000-un_numero%10000)/10000)*((un_numero%10000-un_numero%1000)/1000)*((un_numero%1000-un_numero%100)/100)*((un_numero%100-un_numero%10)/10)*(un_numero%10);
        System.out.println("Valor de producto: " + producto);
    }

}