Showing posts with label coding. Show all posts
Showing posts with label coding. Show all posts

 

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

Java program to print the words starting with a Consonant | JAVA POINT

Java program to print the words starting with a Consonant


Write a Java program to enter a sentence and print the words starting with a Consonant


PROGRAM :


import java.util.*;

class print_consonant

{

   public static void main(String args[])

   {

        Scanner sc=new Scanner(System.in);            

        System.out.println("Enter any sentence: ");

        String s=sc.nextLine();

        s = s+" ";

        int l=s.length();

        int pos=0;

        char ch1, ch2;

        String w;

        for(int i=0; i<l; i++)

        {

            ch1 = s.charAt(i);

            if(ch1 == ' ')

            {

                w = s.substring(pos,i); // extracting words one by one

                ch2 = w.charAt(0);

                if(ch2=='A' || ch2=='E' || ch2=='I' || ch2=='O' || ch2=='U' || ch2=='a' || ch2=='e' || ch2=='i' || ch2=='o' || ch2=='u')

          pos = i+1;                    

                else

          System.out.print(w+" ");

          pos = i+1;

            }

        }

   }

}


/*

 Output :

 Enter any sentence: He is a boy

 He boy

*/

Java program to Check the Disarium Number


Java program to check the Special number | JAVA POINT

Java Program for Special number


Write a Java program to check that a given number is Special number or not.


Special number

If the sum of the factorial of each digit of a number (N) is equal to the number itself, the number (N) is called a Special number or Peterson number or Krishnamurthy Number. 


PROGRAM :


import java.util.Scanner;

public class specialnum
{
 public static void main(String[] args)
 {
        
    int n, num, r,
    sum = 0;
    Scanner sc=new Scanner(System.in);
    System.out.print("Enter the number to check : ");
    n = sc.nextInt();
    num = n;
    while (num > 0)
    {
      r = num % 10;
      int fact=1;
      for(int i=1;i<=r;i++)
      {
        fact=fact*i;
      }
      sum = sum+fact;
            num = num / 10;
    }
    if(n==sum)
    {
     System.out.println("Special Number" );
     }
     else
     {
       System.out.println("Not Special Number" );
        }
    }

}



/*

Output :


Enter the number to be checked : 145

( 145=1!+4!+5!=1+24+120=145 )

145 is a Special number.

*/