Write a Java program to find the Area of the Circle, Rectangle and Triangle.




PROGRAM :

import java.util.*;
class area1
{
  
  public static void main(String[] args) throws InputMismatchException
  {
   Scanner sc = new Scanner(System.in);
   double area;
   
   System.out.println("Main Menu");

   System.out.println("1. Circle");

   System.out.println("2. Ractangle");

   System.out.println("3. Triangle");

   System.out.println("Enter your choice(1,2,3) : ");

   int ch;
   ch=sc.nextInt();

   switch(ch)
   {
    case 1:
         System.out.print("Enter the radius : ");
         double r=sc.nextDouble();

         area=r*r*3.14;
         System.out.println("\nThe area of Circle is : "+area);
         break;

    case 2:
         System.out.print("Enter the length : ");
         double l=sc.nextDouble();

         System.out.print("Enter the width :  ");
         double w=sc.nextDouble();

         area=l*w;
         System.out.println("\nThe area of Ractangle is : "+area);
         break;

    case 3:
         System.out.println("Enter sides of triangle : ");

         System.out.print("Enter side1 : ");
         double a=sc.nextDouble();

         System.out.print("Enter side2 : ");
         double b=sc.nextDouble();

         System.out.print("Enter side3 : ");
         double c=sc.nextDouble();

         double s=(a+b+c)/2;
         area=Math.sqrt(s*(s-a)*(s-b)*(s-c));

         System.out.println("\nThe area of Triangle is : "+area);
         break;

    default:
         System.out.println("Wrong choice !!!");
         break;
    }
  }
}



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.


Java program to find the frequency of each digit in a given number




PROGRAM :


import java.util.Scanner;
 
public class freq
{
 public static void main(String[] args)
 {
  Scanner sc=new Scanner(System.in);
  System.out.println("Enter the number to be checked.");
  int i,j,c;
  int n=sc.nextInt();
  System.out.println("No Freq");
  for(i=0;i<=n;i++)
  {
   c=0;
   for(j=n;j>0;j=j/10)
   {
    if(j%10==1)
    c++;
   }
 
  if(c>0)
   System.out.println("Freq of  "+i+" is "+c);
 }}
}

/*

Output :


Enter the number to be checked : 12121

Freq of 1 is 4 
Freq of 2 is 2

How to Convert a Decimal Number to Binary Equivalent in Java

Write a Java program to convert the decimal number into the binary equivalent.




Java program to convert the decimal into binary


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 binary to decimal equivalent in Java?

How to Convert a Binary Number to Decimal Equivalent in Java?

Write a Java program to convert the binary number into the decimal number.


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 in Java
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.");

    }

}


/*

Output :


Enter the number to be checked : 153

153 is an Armstrong Number.

(Workings 153 = 1*1*1 + 5*5*5 + 3*3*3)

*/


Also read :