Advertisement
Garro

Java - Prueba sumativa 1 - Ejercicio 2

Dec 30th, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. // Pide el ingreso de un numero mayor que el 25 pero menor que el 99.
  2. // Y que el programa imprima ese numero, y al lado, el producto de sus
  3. // digitos, consecutivamente hasta que el producto sea de un solo digito.
  4. // Que repita el proceso en cada linea con el numero ingresado +1 hasta
  5. // llegar al 99. (El programa no imprime cuando el producto es 0).
  6. import java.util.Scanner;
  7. public class siguiente01{  
  8.     public static void main (String args[]){
  9.         int N = leaNumero();
  10.         imprimeSecuencias(N);
  11.     }
  12. public static void imprimeSecuencias(int ini){
  13.     int in = 0;
  14.     int dec = 0;
  15.     int uni = 0;
  16.     for (int i = ini; i<100;i++){
  17.         in = i;
  18.         while (in>=10){
  19.             System.out.print(in+" ");
  20.             dec = (in/10);
  21.             uni = (in - (dec*10));
  22.             in = (uni*dec);
  23.         }if (in!=0){
  24.             System.out.print(in);
  25.         }System.out.println();
  26.     }      
  27. }
  28. public static int leaNumero(){
  29.     Scanner tec = new Scanner(System.in);
  30.     int X = 0;
  31.     boolean error = false;
  32.     do{
  33.         if (error){
  34.             System.out.println("Error! Numero ingresado no estra dentro del rango (26~98).");
  35.         }System.out.print("Ingrese un numero (26~98): ");
  36.         X = tec.nextInt();
  37.         error = true;
  38.     }while(X>=99||X<=25);
  39.     return X;
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement