Showing posts with label Swastika Pattern. Show all posts
Showing posts with label Swastika Pattern. Show all posts

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 Print Swastik Pattern in Java | Best Pattern Programs in Java



java codes for swastik pattern



Write a Java Program to design a Swastik of given size.


In this program, we will learn about how to write the code for Swastik Pattern in Java by using stars, with the user-defined rows and columns.


To get the perfect Swastik shape, the user should input odd numbers for rows and columns so as to find the mid of rows and columns easily.


                   
   *          *  *  *  *
*          *      
*          *  
*  *  *  *  *  *  *
              *          * 
              *          * 
  *  *   *  *          *  


Program:


import java.util.Scanner;

class swastik
{
 public static void main(String args[])
 {
  int n,row, col;

  Scanner sc=new Scanner(System.in);

  System.out.println("Enter the size greater than 4 to get the perfect shape of the Swastik... ");

  n=sc.nextInt();

  if (n%2==0)

      n=n+1;  
      row=n;
      col=n;

  for (int i = 0; i < row; i++)
  {     
   for (int j = 0; j < col; j++)       
   {           
     if (i < (row / 2) )       
     {
      if (j < (col / 2)  )
      {
       if (j == 0)


        System.out.print("*");


       else        

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


      else if (j == (col / 2))

         
        System.out.print(" *");       


      else         


      {
       if (i == 0)       

        
         System.out.print(" *");       
      }       
     }      

     else if (i == (row / 2)  )         


       System.out.print("* ");       


     else         
     { 
      if (j == (col / 2) || j == col - 1)     

      
       System.out.print("* ");
     
      else if (i == row - 1)           
      {


       if (j <= (col / 2) || j == col - 1)                 
         System.out.print("* ");         

  
       else            

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

      else     


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

    System.out.print("\n");
  }
 }
}


/*

Output:


 Enter the number greater than 4 to 

get the perfect shape of the Swastik  


 7


   *          *  *  *  *
*          *      
*          *  
*  *  *  *  *  *  *
              *          * 
              *          * 
  *  *   *  *          *  


*/


Read also :

Java program for Special Numbers

Java program for Armstrong Numbers