Java Program To Find The Frequency Of Each Digit In A Given Number. | JAVA POINT
Write a Java program to find the frequency of each digit in a given number.
PROGRAM :
Output :
How to Convert a Decimal Number to Binary Equivalent in Java
Write a Java program to convert the decimal number into the binary equivalent.
Decimal Number System -
The decimal number system consists of digits from 0 to 9.
Binary Number System -
The binary number system consists of only two digits which are 0 and 1.
PROGRAM :
import java.util.Scanner;
public class DecimalBinary
{
public static void main(String args[])
{
int dec, q, i=1, j;
int bin[] = new int[100];
Scanner scan = new Scanner(System.in);
System.out.print("Enter a Decimal Number : ");
dec = scan.nextInt();
q = dec;
while(q != 0)
{
bin[i++] = q%2;
q = q/2;
}
System.out.print("Equivalent Binary number is: ");
for(j=i-1; j>0; j--)
{
System.out.print(bin[j]);
}
System.out.print("\n");
}
}
Output:
Enter a Decimal Number : 45
Equivalent Binary number is: 101101
Also read:
How to Convert a Binary Number to Decimal Equivalent in Java?
Write a Java program to convert the binary number into the decimal number.
Decimal Number System -
The decimal number system consists of digits from 0 to 9.
Binary Number System -
The binary number system consists of only two digits which are 0 and 1.
PROGRAM :
import java.util.Scanner;
class bintodec
{
public static void main(String args[])
{
int p=0,d=0,t=0,tmp=0;
Scanner sc=new Scanner(System.in);
System.out.print("\nEnter the binary no.: ");
int b=sc.nextInt();
System.out.print("\nThe decimal equivalent
of "+b+" is : ");
while(true)
{
if(b==0)
{
break;
}
else
{
tmp=b%10;
t=tmp*(int)Math.pow(2,p);
d=d+t;
b=b/10;
p++;
}
}
System.out.print(d);
}
}
Output :
Enter the binary no.: 10101
The decimal equivalent of 10101 is : 20
Read also :
How to convert decimal to binary program in Java?
Java Program to Check the Armstrong numbers | JAVA POINT Numbers
Java Program to Check the Armstrong numbers
![]() |
Armstrong number |
Armstrong number
A number will be called Armstrong if the sum of cubes of each digits is equal to the original number.
Program
import java.util.Scanner;
public class Armstrong
{
public static void main(String args[])
{
Scanner ob=new Scanner(System.in);
System.out.println("Enter the number to be checked.");
int num=ob.nextInt();
int a,i,sum=0;
i=num;
while(num!=0)
{
a=num%10;
sum=sum+a*a*a;
num=num/10;
}
if(sum==i)
System.out.println(i+" is an Armstrong Number.");
else
System.out.println(i+" is not a Armstrong Number.");
}
}