GFG mathematics 1
package com.company;
import java.lang.*;
import java.util.Scanner;
import static java.lang.Math.floor;
public class CWR_Mathematics_Gfg {
// Finding trailing zeroes in a factorial
public static int findZero(long n){
long a = giveFactorial(n);
int count = 0;
while(a%10==0){
count++;
a = a/10;
}
return count;
}
// Factorial
public static long giveFactorial(long n){
if(n==0 || n==1){
return 1;
}
return n*giveFactorial(n-1);
}
// Method 2
public static boolean isNumPalindrome(int n){
int rev = 0;
int temp =n;
while(temp>0){
rev = rev *10 + temp%10;
temp= temp/10;
}
return (rev == n) ;
}
//Method 1
public static boolean isPalindrome(int n){
int a= countDigit1(n);
if(a==1){
return true;
}
if(a>1){
int c = 0;
int [] digit = new int[a];
for(int i=0;i<a-1;i++){
c = n%10;
n = n/10;
digit [i] = c;
}
digit [a-1] = n;
for(int j=0 ; j<digit.length; j++){
if(digit [j] == digit[digit.length-1-j] ){
continue;
}
else{
return false;
}
}
}
return true;
}
public static int countDigit1(long n){
int count = 0;
while(n!=0){
n=n/10;
count++;
}
return count;
}
public static int countDigit2(long n){
if(n==0){
return 0;
}
return 1+countDigit2(n/10);
}
public static double contDigit3(long n){
return ( Math.floor((Math.log(n)/Math.log(10))+1));
}
public static void main(String[] args) {
// Number of digits in a number.
// Method--1
// System.out.println(countDigit1(12300000));
//
//// Method 2 recursive
// System.out.println(countDigit2(748745385));
//
//// Method 3 Logarithmic
// System.out.println(contDigit3(123));
System.out.println("Enter the number");
Scanner sc = new Scanner(System.in);
System.out.println(findZero(sc.nextInt()));
}
}
Comments
Post a Comment