Sunday, 12 January 2020



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---

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...