program to count the digits in a given number and square of it.
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.print("enter the number=");
int num=sc.nextInt();
digit obj=new digit();
obj.number(num);
}
}
class digit{
int rm,cn=0;
void number(int n){
while(n>0){
rm=n%10;
cn+=1;
n/=10;
}
System.out.println("digits in number="+cn);
System.out.print("the square of no. of digits in number="+(cn*cn));
}
}
■》output->
enter the number=56704
digits in number=5
the square of no. of digits in number=25
Comments
Post a Comment