Sunday, 24 January 2021

lucky number less the in range of natural number n

import java.io.*;
class lucky1
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("entre the range of natural no");
        int n=Integer.parseInt(br.readLine());
        int a[]=new int[n];
        for(int i=0;i<n;i++)
        {a[i]=i+1;
        }
        if(n<1)
        {
            System.out.println("invalid number");
        }
            else
            {
                int c=2;
            
                int t=0;
                while(n>=c)
                {
                    for(int i=c-1;i<n;i=i+c)
                     {
                         a[i]=0;
                         
                        }
                        for(int i=0;i<n;i++)
                        {
                            if(a[i]==0)
                            {
                                
                                for(int j=i;j<n-1;j++)
                                {
                                    t=a[j];
                                    a[j]=a[j+1];
                                    a[j+1]=t;
                                }
                                n=n-1;
                            }
                            
                        }
                        
                        c=c+1;
                    }
                        for(int i=0;i<n;i++)
                        {
                            System.out.print(a[i]+",");
                        }
              }
            }
        }

to print the upper half of a metrix n*n

import java.io.*;
class pppp
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("entre the n for array(n*n");
        int n=Integer.parseInt(br.readLine());
        int a[][]=new int[n][n];
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                a[i][j]=Integer.parseInt(br.readLine());
            }
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(i>j)
                {
                    System.out.print(" ");
                }
                else
                {
                    System.out.print(a[i][j]);
                }
                
            }
            System.out.println();
        }
    }
}

to print the world with no vovel

import java.io.*;
class vovel
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("entre the  sentences");
        String s2=br.readLine();
        String s1="";
        s2=s2+"  ";
        int l=s2.length();
        
        
        int l2=0;boolean found=false;;
        for(int i=0;i<l;i++)
        {
               if(s2.charAt(i)==' ')
                {
                   for(int j=l2;j<=i;j++)
                   {
                    if(s2.charAt(j)=='a'||s2.charAt(j)=='e'||s2.charAt(j)=='i'||s2.charAt(j)=='o'||s2.charAt(j)=='u')
                    {
                        found=true;
                        break;
                    }
                }
                    
                    if(found==false)
                     {
                       for(int k=l2;k<=i;k++)
                       {
                           s1=s1+s2.charAt(k);
                        }
                      
                    }
                    System.out.println(s1);
                     s1="";
                    found=false;
                    l2=i+1;
                    
                }
                    
            }
                
            }
        }

coded decoded

import java.io.*;
class code
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("entre the code");
        String c=br.readLine();
        int l=c.length();
        String b="";String e="";
        for(int i=l-1;i>=0;i--)
        {
            b=b+c.charAt(i);
        }
        String d="";
        int a=0;
        int dd=0;
        
        while(a<l-1)
        {
            d=b.substring(a,a+2);
            dd=Integer.parseInt(d);
            if(dd==32||(dd>=65&&dd<=90)||(dd>=97&&dd<=99))
            {
                e=e+(char)dd;
                a=a+2;
            }
             else
             {
                 
                d=b.substring(a,a+3);
                dd=Integer.parseInt(d);
               if(dd>99&&dd<=122)
                 {
                    e=e+(char)dd;
                    a=a+3;
            
                }
                
                  }}System.out.println("decoded messege ="+e);
        
    
}}

program to accept no of sentences from user and also the sentences and print the no of words without vovels and consicutive alphabets in each sentences and print the reverse sentence

import java.io.*;
class abc
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("entre the number of sentences");
        int n=Integer.parseInt(br.readLine());
        String s1[]=new String[n];
        for(int i=0;i<n;i++)
        {
            System.out.println("entre the "+(i+1)+"sentene");
            s1[i]=br.readLine();
        }
         for(int i=0;i<n;i++)
         {
            String s2="";
            String s3="";
            int c=0;
            int c1=0;
            int c2=0;
            String s="";
            s=s1[i];
            s=s+" ";
            int l=s.length();
            int l2=0;
            for(int j=0;j<l;j++)
            {
                if(s.charAt(j)==' ')
                {
                    for(int k=l2;k<=j;k++)
                    {
                        if(s.charAt(k)=='a'||s.charAt(k)=='e'||s.charAt(k)=='i'||s.charAt(k)=='o'||s.charAt(k)!='u')
                        {
                            c=c+1;
                            break;
                        }
                    }
                    if(c==0)
                    {
                        c1=c1+1;
                    }
                    
                    for(int k=l2;k<j-1;k++)
                     {
                         if(s.charAt(k)==s.charAt(k+1))
                         {
                             c2=c2+1;
                             break;
                            }
                        }
                       for(int k=l2;k<j;k++)
                          {
                              s2=s2+s.charAt(k);
                            }
                       l2=j+1;
                       s3=" "+(s2+s3);
                       s2="";
                       c=0;
                    }
                    
                       
                }
               System.out.println("no of words without vovel in "+i+1+"sentence="+c1);   
                 System.out.println("no of words with consiqutive alphabets in "+i+1+"sentence="+c2);
                  System.out.println(s3);
                }
            }
        }
        



write a program ro accept numbers M and N from user and print the smallest required number whose sum of all digits is equal to n .where n is less then 100 and m is between 100&10000

import java.io.*;
class small
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("entre the value of m");
        int m=Integer.parseInt(br.readLine());
        System.out.println("entre the value of n");
        int n=Integer.parseInt(br.readLine());
        int r=0;int num=0;int t=0;
        if((m>100&&m<10000)&&(n<100))
        {
            for(int i=m;i<10000;i++)
            {
                r=0;
                int rev=0;
                int d=0;
                t=i;
                while(t>0)
                {
                    d=t%10;
                    rev=rev*10+d;
                    r=r+d;
                    t=t/10;
                }
                if(r==n)
                {
                    while(rev>0)
                    {
                        d=rev%10;
                        num=num*10+d;
                        rev=rev/10;
                    }
                    System.out.println("reqired number is ="+num);
                    break;
                }
            
           }
       }
       else
       System.out.println("invalid no");
    }
}





frequency of an element in an array


import java.io.*;
class freq
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("entre the number of digits");
        int n=Integer.parseInt(br.readLine());
        int f=0;
        System.out.println("entre the numbers");
        int a[]=new int[n];
        for(int i=0;i<n;i++)
        {
            a[i]=Integer.parseInt(br.readLine());
        }
        for(int i=0;i<n;i++)
        {
            int c=0;
            int c1=0;
            f=a[i];
            for(int j=i-1;j>=0;j--)
            {
               if(a[i]==a[j])
               {
                   c=c+1;
                }
            }
            if(c==0)
            {
                for(int j=i;j<n;j++)
                {
                    if(a[i]==a[j])
                    {
                        c1=c1+1;
                    }
                }
                System.out.println("frequency of"+a[i]+"is ="+c1);
            }
        }
    }
}

Friday, 22 January 2021

program of printing prime pairs betwee given no whose sum is equal to the given number

import java.io.*;
class pair
{
    public static void main(String args[])throws IOException
    {   int n=0;
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("entre any number");
        n=Integer.parseInt(br.readLine());
        int c1=0;
        int c=0;
        int t=0;
        int a[]=new int[n];
        if(n%2==0&&n>9&&n<50)
        {
        for(int i=2;i<=n;i++)
        {
            for(int j=1;j<=i;j++)
            {
                if(i%j==0)
                {
                    c=c+1;
                }
            }
            if(c==2)
            {
                a[t++]=i;
                c1=c1+1;
            }
            c=0;
        }
        for(int i=0;i<=c1/2;i++)
        {
            int k=a[i];
            for(int j=0;j<=c1;j++)
            {
                if(k+a[j]==n)
                {
                    System.out.print(k+","+a[j]);
                }
            }
            System.out.println();
        }
    }
    else
    System.out.println("given number is odd");
    }
}

program of class 11th to take date/month/year and ceck the date is valid or not if valid then print the number of days

import java.io.*;
class valid
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("entre the date");
        int d=Integer.parseInt(br.readLine());
        System.out.println("entre month");
        String s=br.readLine();
        System.out.println("entre year");
        int y=Integer.parseInt(br.readLine());
        int t=0;
        String month[]={"january","february","march","aprai","may","june","july","august","september","october","november","december"};        
        int year[]={31,28,31,30,31,30,31,31,30,31,30,31};
        if(y%4==0)
        {
            year[1]=29;
        }for(int i=0;i<12;i++)
           {
               if(s.equalsIgnoreCase(month[i]))
               {
                   t=i;
                }
            }
        if(d<=year[t])
        {
           for(int i=0;i<12;i++)
           {
               if(s.equalsIgnoreCase(month[i]))
               {
                   t=i;
                }
            }
            for(int i=0;i<t;i++)
            {
                d=d+year[i];
            }
            System.out.println(d+"days"+y);
        }
        else
        System.out.println("invalid date");
    }
}
    
          

program for class 11th to take days and year and print in full forms like in dd/mm/yyyy

import java.io.*;
class date
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("entre the days between 1 and 366");
        int d=Integer.parseInt(br.readLine());
        System.out.println("entre the year");
        int y=Integer.parseInt(br.readLine());
        String month[]={"january","february","march","aprai","may","june","july","august","september","october","november","december"};
        int year[]={31,28,31,30,31,30,31,31,30,31,30,31};
        if(y%4==0)
        {
            year[1]=29;
        }
        int i=0;
        for(i=0;i<12;i++)
        {
            if(d>=year[i])
            {
                d=d-year[i];
            }
            else
            {
            break;
            }
        }
        System.out.println(d+"/"+month[i]+"/"+y);
    }
}

class 11 th program of java for the data of party date of friends

import java.io.*;
class party
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       System.out.println("enter the number of friends ");
         int n=Integer.parseInt(br.readLine());
         int i,j;
         int free[][]=new int[n][31];
         if(n>1)
         {
         for(i=0;i<n;i++)
         {
             System.out.println("enter the freeb date of friend="+(i+1));
             for(j=0;j<31;j++)
             {
                 free[i][j]=Integer.parseInt(br.readLine());
                 if(free[i][j]==0)
                 {
                     break;
                    }}} int arr1[]=new int[31];int x=0;
       for(i=0;i<31;i++)
       {int temp=free[0][i];int c=0;
           for(j=1;j<n;j++)
           {
                  for(int k=0;k<31;k++)
                  {
                      if(temp==free[j][k]&&temp!=0)
                      {
                         c=c+1;
                        }
                    }
                    if(c==(n-1))
                    { 
                       arr1[x]=temp;x++;
                }               
                
            }
        }
        if(x>2)
        {System.out.print("Suitable date for party is ");
            for(i=0;i<x-2;i++)
            {
                System.out.print(arr1[i]+",");
            }
            System.out.print(arr1[x-1]+"and"+arr1[x-2]);
        }
    else if(x==2)
{
    System.out.print("Suitable date for party is ");
    System.out.print(arr1[0]+"and"+arr1[1]);
}
else
{
System.out.print("suitable date for party is "+arr1[0]);}}
else{
    System.out.println("he may be always free on such date");
}
}}
    

Thursday, 14 January 2021

program of class 11 for marks percentage of best 5 subjects

HAY THANK FOR VISIT



answer:-


import java.util.*;
class ICSE
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("entre marks of english");
        int a=sc.nextInt();
        int sub[]=new int[6];
        int i,j,t=0,s=0;
        System.out.println("entre marks of science,maths.h.civics,c.a,geo,hindi");
        for(i=0;i<6;i++)
        {
            sub[i]=sc.nextInt();
        }
        for(i=0;i<5;i++)
        {
            for(j=0;j<6-i-1;j++)
            {
                if(sub[j]<sub[j+1])
                {
                    t=sub[j+1];
                    sub[j+1]=sub[j];
                    sub[j]=t;
                }
            }
        }
        System.out.print("percent marks=");
        for(i=0;i<5;i++)
        {
            s=s+sub[i];


        }
        s=s+a;
        System.out.println((double)s/6);
    }
}


HAY THANK FOR VISIT'
Question:-write a program with a class name twist that accepts a number,N,that has even number of digits.
creat a new number N2 from N,such that each pair of digits from lest side are reserved. in casae N has odd numbers of digit N2=N

answer:-


import java.util.*;
class TWIST
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        System.out.println("enter the number ");
        int n=sc.nextInt();
        int t=n;int c=0;int i;int n1=0;
        while(t>0)
        {
            
            c=c+1;
            n1=n1*10+(t%10);
            t=t/10;
        }             
        int arr[]=new int[c];
        t=0;
        if(c%2==0)
        {
            for(i=0;i<c;i++)
            {
                arr[i]=n1%10;
                n1=n1/10;
            }
            for(i=0;i<(c/2);i=i+2)
            {
                t=arr[i];
                arr[i]=arr[i+1];
                arr[i+1]=t;
            }for(i=0;i<c;i++)
            {
                
            System.out.print(arr[i]);
        }
        }
        else
        {
            System.out.println(n);
        }
}
}

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