You are on page 1of 1

//Hallar el factorial de un numero.

import java.util.*;
class Factorial{
 public static void main(String arg[]){
  Scanner in = new Scanner(System.in);
  System.out.println("Digite un numero mayor o igual que 0");
  long valor = Integer.parseInt(in.next());
  if(valor==0){
   System.out.println("El factorial de "+valor+" es 1");
  }else{
    int temp=1;
    for(int i=1;i<=valor;i++){
     temp*=i;//Es lo mismo que temp=temp*i
  }
    System.out.println(""+temp);
 }
 }
}

import java.io.*;

class Cifras {

static int total=0;


static int x=0;

static int numCifras(int x){


while(x!=0){
x=x/10;
total+=1; //incrementamos el contador
}
return total;
}

public static void main(String[]args) throws IOException{


//BufferedReader para leer de consola
BufferedReader leer = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Introduce un nu4mero:");
//leemos una línea como string
String linea = leer.readLine();
/*Convertirmos el string a un número. Podrías poner
*un try y catch para comprobrar errores al convertirlo.Por
*ejemplo si introducen un string*/
x= Integer.parseInt(linea);
System.out.println("El numero de cifras es:");
//Imprimimos el número de líneas
System.out.println(numCifras(x));
}
}

You might also like