Sunday, 12 January 2020

QUESTION:-BUBBLE SORT




class bs
{
    void main(int a[])
    {
        int l=a.length;
        for(int i=0;i<l-1;i++)
    {
            
            for(int j=0;j<l-1-i;j++)
            {
                if(a[j]>a[j+1])
                 {
                     int t=a[j];
                     a[j]=a[j+1];
                     a[j+1]=t;
                    }
                }
            }
            for(int i=0;i<l;i++)
            {
                System.out.println(a[i]);
            }
        }

    }
QUESTION:-SELECTION SORT


class ss
{
    void main(int a[])
    {
        int l=a.length;
    for(int i=0;i<l-1;i++)
    {
        int min=a[i];
        int p=i;
        for(int j=i+1;j<l;j++)
        {
            if(a[j]<min)
            {
               p=j;
               min=a[j];
            }
        }
           int t=a[i];
            a[i]=a[p];
            a[p]=t;
            
           
    
    }
          for(int i=0;i<l;i++)
    {
    System.out.println(a[i]);
    }
}

}
QUESTION:-BINARY SEARCH


import java.util.*;
class binary
{
    void main()
    {int k=1;
        Scanner sc=new Scanner(System.in);
        System.out.println("ente the number to be search for");
        int x=sc.nextInt();
        int a[]=new int[10];boolean found=false;
         for(int i=0;i<10;i++)
        {
            System.out.println("enter the "+k+" number ");
           a[i]=sc.nextInt();
           k=k+1;
        }
        int low=0;
        int u=l-1;
        int p=0;
        while(low<=u)
        {
            int mid=(low+u)/2;
            if(a[mid]==x)
            {found=true;
                p=mid+1;
                break;
            }
            else
            {
                if(a[mid]<x)
                {low=mid+1;
                }
                else
                u=mid-1;
            }
            }
            System.out.println("no to be found="+p);
            if(found==true)
            System.out.println("search sucessfull");
            else
            System.out.println("search unsecessfull");

        }
}


QUESTION:-LENEAR SEARCH



import java.util.*;
class lelenar
{
    void main()
    {int k=1;
        Scanner sc=new Scanner(System.in);
        System.out.println("ente the number to be search for");
        int x=sc.nextInt();
        int a[]=new int[10];
        for(int i=0;i<l;i++)
        {
            System.out.println("enter the "+k+" number ");
           a[i]=sc.nextInt();
           k=k+1;
        }
        boolean found=false;int p=0;
        for(int i=0;i<10;i++)
        {
            if(a[i]==x)
            {
                found=true;
                p=i+1;
                break;
            }
        }
        System.out.println("the position of no is"+p);
        if(found==true)
        System.out.println("search sucessfull");
            else
            System.out.println("search unsuccesfull");
        }

    }
HAY THANK FOR VISIT


Question:-Write a program  to print a sreing array and print the largest.

class lar
{
    void main(String s[])
    {
        int l=0;
       String lar=s[0];
       for(int i=1;i<s.length;i++)
       {
           l=s[i].length();
           if(l>lar.length())
           {
               lar=s[i];
            }
        }
        System.out.println("longest string is"+lar);
    }

}
HAY THANK FOR VISIT


Question:-Store the name of 10 countries and tgheir correspoinding capital in turn reaspectively . input the name of the country and search.

import java.util.*;
class Country
{
    void main()
    {
        Scanner sc=new Scanner(System.in);
        String name[]={"india","pakistan","afganistan","australia","canada","germany","france","nepal","iran","iraq"};
        String cap[]={"new delhi","Islamabad","kabul","canberra","ottawa","berlin","paris","kathmandu","tehran","baghdad"};
        System.out.println("entre the name of country");
        String n=sc.nextLine();
        n=n.toLowerCase();
        
        for(int i=0;i<10;i++)
       {
          if(n.equals(name[i]))
          {
              System.out.println(n+"="+cap[i]);
            }
        }
    }

}
HAY THANK FOR VISIT


Question:-Write a program to print the smallest number in array.


class Small

{


      void main(int a[])
            {
               int l=a.length;
                int s=a[0];
                 int p=0;
                 for(int i=1;i<l;i++)
                      {
                            if(a[i]<s)
                              {
                                 s=a[i];
                                 p=i;
                               }
                        }
         System.out.println("the smallest element  in the arayyis"+s);
          System.out.println("position of element is"+p);

                 }
  }

HAY THANK FOR VISIT

Question:-write a program to print the pattern given below:-
                  
                5 4 3 2 1
                5 4 3 2
                        5 4 3
                5 4 
                5
              
                 class Pat2
                   {
                      void main()
                        {
                              for(int i=5;i>=1;i--)
                                 {
                                      for(int j=5;j>=i;j--)
                                        System.out.printl(j);
                                     System.out.println();
                                  }
                            }
                    }
                     

Thanks for visit Keep Supporting.

Monday, 6 January 2020

HAY THANK FOR VISIT

<<<<<<LET'S START WITH ANOTHER QUESTION>>>>>>>>>>>>>

QUESTION-----TO PRINT THE PATTRAN GIVEN BELOW:-

                      1
                      12
                      123
                      1234
                      12345

class PAT1
{
  void main()
  {
      for(int i=1;i<=5;i++)
      {
          for(int j=1;j<=i;j++)
          System.out.print(j);
        System.out.println();
      }
    }
}

OUTPUT---
HAY THANK FOR VISIT

<<<<<<LET'S START WITH ANOTHER QUESTION>>>>>>>>>>>>>

QUESTION---TO CHECK THAT THE  GIVEN NUMBER IS PALENDROM OR NOT..


class Palendrom
{
    void main(int n)
    {
        int d=0;int rev=0;int t=n;
        while(n>0)
        {
            d=n%10;
            rev=rev*10+d;
            n=n/10;
        }
        n=t;
        if(n==rev)
        System.out.println("Palendrom number");
        else
        System.out.println("not a Panlendrom number");
    }
}

input---121
output---
HAY THANK FOR VISIT

<<<<<<LET'S START WITH ANOTHER QUESTION>>>>>>>>>>>>>

QUESTION --- TO CHECK THAT THE GIVEN NUMBER IS PERFECT NUMBER OR NOT.

class Perfect
{
    void main(int n)
    {
        int f=0;
        for(int i=1;i<n;i++)
        {
            if(n%i==0)
            f=f+i;
        }
        if(f==n)
        System.out.println("perfect number");
        else
        System.out.println("not a perfect number");
    }
}


INPUT--6
OUTPUT--


HAY THANK FOR VISIT



<<<<<<<LET's START WITH ANOTHER QUESTION>>>>>>>>


QUESTION---WRITE A PROGRAM TO PRINT THE FACTORIAL OF A NUMBER..



class Factorial
{
    void main(int n)
    {
        int m=1;
        for(int i=1;i<=n;i++)
        {
            m=m*i;
        }
        System.out.println("factorial of the number is "+m);
    }
}







INPUT--------5
OUTPUT-------------




HAY THANK FOR VISIT

<<<<<<<LET's START WITH ANOTHER QUESTION>>>>>>>>

Question:-PRINTING THE TABLE OF THE GIVEN NUMBER...


class Table
{
    void main(int n)
    {
        for(int i=1;i<=10;i++)
        {
            System.out.println(n*i);
        }
    }

}

INPUT----2
OUTPUT:----------------

HAY THANK FOR VISIT

<<<<<<<LET's START WITH ANOTHER QUESTION>>>>>>>>>>>>>>>

Question--Write a program to read the month number and print the name of that month.


import java.util.*;
class Month
{
    void main()
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("entre the month number");
        int n=sc.nextInt();
        switch(n)
        {
            case 1:
            System.out.println("January");
            break;
            case 2:
            System.out.println("February");
            break;
            case 3:
            System.out.println("March");
            break;
            case 4:
            System.out.println("Aprail");
            break;
            case 5:
            System.out.println("May");
            break;
            case 6:
            System.out.println("June");
            break;
            case 7:
            System.out.println("july");
            break;
            case 8:
            System.out.println("August");
            break;
            case 9:
            System.out.println("September");
            break;
            case 10:
            System.out.println("October");
            break;
            case 11:
            System.out.println("November");
            break;
            case 12:
            System.out.println("December");
            break;
            default:
            System.out.println("invalid input");
        }
    }
}
     
INPUT----5
OUTPUT----MAY


        IF THIS BLOG IF USEFUL FOR YOU THEN SHARE IT WITH YOUR FRINDS AND LIKE COMMENT ON THIS BLOG HOW IS THIS BLOG..............
HAY THANK FOR VISIT
TODAY I AM GIVING A SMALL PROGRAM FOR CHECKING THE GRATEST AMONG TWO NUMBERS.

<<<<<<<<<<<HAY THERE LETS START>>>>>>>>>
QUESTION :-Write  a program to  read two numbers and find the gratest number.

class abc
{
    void main(int a,int b)
    {
        if(a>b)
        System.out.println("the grater no is"+a);
        else
        System.out.println("the greater no is"+b);
    }
}

Program(python):-Find duplicates in an array (Geeks for geek problem)

QUESTION:- Given an array  a  of size  N  which contains elements from  0  to  N-1 , you need to find all the elements occurring more than o...