Search This Blog

Loading...

Thursday, August 18, 2016

Pattern of any particular digit



In this program we will display a pattern using any particular digit, say 5. The pattern would look like:

55555
55
55
55
55555


class Pat
{
 int i,j,k,x=5;
public void show()
{
  for(i=0;i<=4;i++)
{
 if(i==0 || i==4)
k=4;
else
k=1;
for(j=0;j<=k;j++)
System.out.print(x);
System.out.println();
}
public static void main(String args[])
{
 Pat ob=new Pat();
ob.show();
}
}

Friday, April 1, 2016

BlueJ Program to find the Words with vowel from a sentence



 In this program, user will enter a sentence and program will display the Words with at least one vowel.

  Codes of the program is given below

import java.io.*;
public class Vowel
{
    String st1,st2;
    BufferedReader br =new BufferedReader (new InputStreamReader(System.in));
    int i;
 
    public Vowel ()
    {
      
    }

   public void takeSentence() throws Exception
   {
        System.out.println("Enter the sentence:");
        st1=br.readLine();
                System.out.println("Words containing vowels: ");
        while(true)
        {
             i=st1.indexOf(" ");
             if(i==-1)
             break;
             st2=st1.substring(0,i);
             st1=st1.substring(i+1);
            if(vowel(st2))
            System.out.print("  "+st2);
                
            }
            if(vowel(st1))
            System.out.print("  "+st1);
            }
            public boolean vowel(String s)
            {
                 int i, len,c=0;
                 s=s.toLowerCase();
                 len=s.length()-1;
                 for(i=0;i<=len; i++)
                 {
                      switch(s.charAt(i))
                      {
                           case 'a':
                           case 'e':
                           case 'i':
                           case 'o':
                           case 'u':
                           c=1;
                        }
                         if(c==1)
                         break;
                        }
                        if(c==1)
                        return true;
                        else
                        return false;
                    }
            public static void main(String args[])throws Exception
            {
                 Vowel ob=new Vowel ();
                 ob.takeSentence();
                }
            }
      

Details and Technical analysis of the program


 In this program I have used 'indexOf ()' and 'substring ()' functions of String class to break the sentence
 into Words. Function 'indexOf ()' has many overloaded versions and in this program the function taked a string value as argument and searches the
 string value in the invoking string object. The function returns the first location of the argument string if found and if
 the argument value is not present in the invoking string object it returns -1.

'substring ()' function extracts a part of the invoking string depending on the argument. The call 'st2=st1.substring(0,i);'
extracts a Word and the second call 'st1=st1.substring(i+1);' extracts the remaining string.

From the loop body, each word is passed to another user defined function 'public boolean vowel (String s)'
function and this function returns true if the argument string value contains at least one vowel or returns false.




The same program using StringTokenizer class (For ISC students)

import java.io.*;
import java.util.*;
public class Vowel
{
    String st1,st2;
    BufferedReader br =new BufferedReader (new InputStreamReader(System.in));
    StringTokenizer st;
    int i;
 
    public Vowel ()
    {
      
    }

   public void takeSentence() throws Exception
   {
        System.out.println("Enter the sentence:");
        st1=br.readLine();
        st=new StringTokenizer(st1);
                System.out.println("Words containing vowels: ");
        while(st.hasMoreTokens())
        {
            st1=st.nextToken();
           
            if(vowel(st1))
            System.out.print("  "+st1);
            }
        }
            public boolean vowel(String s)
            {
                 int i, len,c=0;
                 s=s.toLowerCase();
                 len=s.length()-1;
                 for(i=0;i<=len; i++)
                 {
                      switch(s.charAt(i))
                      {
                           case 'a':
                           case 'e':
                           case 'i':
                           case 'o':
                           case 'u':
                           c=1;
                        }
                         if(c==1)
                         break;
                        }
                        if(c==1)
                        return true;
                        else
                        return false;
                    }
            public static void main(String args[])throws Exception
            {
                 Vowel ob=new Vowel ();
                 ob.takeSentence();
                }
            }
           
         
           

Sample input and output


Enter the sentence:
This is a typical my style
Words containing vowels:
  This  is  a  typical  style


Thursday, March 31, 2016

BlueJ Program to find the word with maximum length in a sentence


 In this program, user will enter a sentence a program will display the word with maximum length from the program.

  Codes of the program is given below

import java.io.*;
public class Word
{
    String st1,st2,maxSt;
    BufferedReader br =new BufferedReader (new InputStreamReader(System.in));
    int i,max=0;
 
    public Word()
    {
      
    }

   public void takeSentence() throws Exception
   {
        System.out.println("Enter the sentence:");
        st1=br.readLine();
        while(true)
        {
             i=st1.indexOf(" ");
            if (i== -1)
            break;
             st2=st1.substring(0,i);
             st1=st1.substring(i+1);
            if(st2.length() >max)
            {
                 max=st2.length();
                 maxSt=st2;
                }
            }
           if(st1.length() >max)
            {
                 maxSt=st1;
                }
                System.out.println("The word with maximum length="+maxSt);
            }
            public static void main(String args[])throws Exception
            {
                 Word ob=new Word();
                 ob.takeSentence();
                }
            }
           

Details and Technical analysis of the program


 In this program I have used 'indexOf ()' and 'substring ()' functions of String class to break the sentence into words. Function 'indexOf ()' has many overloaded versions and in this program the function taked a string value as argument and searches the string value in the invoking string object. The function returns the first location of the argument string if found and if the argument value is not present in the invoking string object it returns -1.

'substring ()' function extracts a part of the invoking string depending on the argument. The call 'st2=st1.substring(0,i);' extracts a word and the second call 'st1=st1.substring(i+1);' extracts the remaining string.

The loop ends when there is only one word and so at the end of the loop, the last word is again checked.



The same program using StringTokenizer class (For ISC students)

import java.io.*;
import java.util.*;
public class Word
{
    String st1,st2,maxSt;
    BufferedReader br =new BufferedReader (new InputStreamReader(System.in));
    int i,max=0;
    StringTokenizer st;
 
    public Word()
    {
      
    }

   public void takeSentence() throws Exception
   {
        System.out.println("Enter the sentence:");
        st1=br.readLine();
       st=new StringTokenizer (st1);
           while(st.hasMoreTokens())
           {
                st2=st.nextToken();
                if(st2.length()>max)
            {
                 maxSt=st2;
                 max=st2.length();
                }
            }
                System.out.println("The word with maximum length="+maxSt);
            }
            public static void main(String args[])throws Exception
            {
                 Word ob=new Word();
                 ob.takeSentence();
                }
            }
           

Sample input and output


Enter the sentence:
This is a test of max length test

The word with maximum length=length

Wednesday, February 17, 2016

Download ebooks


It is observed that school and Engineering students are always in search of good tutorial ebooks from the net. This page is specially for those students who are looking for quality ebooks. From this page you can download ebooks of  C Language, C++, Data Structure through C (all for Engineering college students) and BlueJ (for ICSE and ISC students).

Click on the following links to download the ebooks.


For ICSE / ISC students




Few of the comments

Kothari Keval
May 28, 2011 at 12:36 AM
Thank you very much sir..... I am MCA students and confused in address calculation and Row and Column representation of arry. The books i have which is very complicated. Your tutorial is so easy so any one can learn it easily.
Thanks...

PANCHI DOBREAL
February 19, 2012 at 9:35 AM
SIR WE ALL ARE VERY THANKFUL TO YOU AND RECEIVING GERAT HELP FROM U ON BEHALF OF ALL SITE LINKERS I THANK U FOR 

UR HELP

Matt Shadows
August 25, 2012 at 12:42 AM
sir, ur programs are really helpful for ne kind of practical exams be it isc or school level.....
thank u sir....

AnonymousOctober 2, 2012 at 6:53 PM
A very very Good website sir.

fioOctober 3, 2012 at 12:45 AM
your programs have been very helpful sir...thank you






For Engineering students


C Language

Data Structure through C (coming soon...)

C++ Language (coming soon...)

Your comments on the books are highly appreciated.


Friday, January 22, 2016

ICSE Computer Application Paper 2016 Guess Questions and Solutions


In this article students appearing in ICSE 2016 may get suggestions for Computer Application paper. Some of the answers are lengthy but it actually covers answer of two or more questions in one answer. Best of Luck!


     1.    What are the access specifiers used in Java

Ans: There are four access specifiers in java – public, private, protected and default. Members with public specifers can be accessed from any where, even from outside the package. Members with private specifers can be accessed from only within the class. Members with protected specifers can be accessed from sub classes only.

      2.    Differentiate between == and equals () method

Ans: == is a relational operator which is used to check equality of two primitive values. The same operator can be used on objects to check the equality of references, not value.
The equals () method is a String class method which is used to check whether the invoking String object and the argument String objects have same value or not. The method returns boolean value.

     3.    Differentiate between call by value and call by reference

Ans: Both are method calling techniques while call by value uses variable as arguments and call be reference uses objects as arguments.
Call by value can not modify actual argument values after the execution of function but call by reference can modify actual argument values.

    4.    What is actual parameter and formal parameter

Ans:  Actual arguments are the variables or objects used in function calling statement and formal arguments are the variables or objects declared in argument zone of a function definition.

    5.    Between binary and linear search, which one is better and why

Ans: Linear searching technique is better that binary search as this technique don’t have any preconditions like binary search. Linear search can be performed with the elements stored in as it is condition and this storing technique can be applied for unique value search as well as category wise search.
6.    What are the preconditions of binary search
For binary search, the elements should be in sorted order and the middle location value can be accessed directly.

     7.    What is instance variable and method

Instance members – both variable and method are those whose existence comes after creating the object and can be used after creating object. For each objects of a class, separate copies of instance variables are created while only one copy of function will be created for any number of objects.

Download eBook on BlueJ 

    8.    What is constructor and how it differs from a normal function

Constructor is a special function whose execution is must for creating object.

   Comparison between constructor and normal function

Constructor
Function
Constructor name must be the same as the class name.
Function name should not match with the class name.
Constructor has no return type, not even void.
Function must have a return type.
If constructor is not defined in a class, compiler supplies default constructor.
There is no such concept of default function

9.    What is default constructor
Default constructor is that constructor which is supplied by compiler during creation of an object if there is no constructor defined in a class. Default constructor is always empty body withour argument constructor.
Example of default constructor:
Suppose a class named MyClass is defined, Default constructor of MyClass looks like:
MyClass ()
{
}

    10. What is difference between default constructor and normal constructor

Default constructor is supplied by compiler while normal constructors are defined by programmers.

     11. What is exception handling

Exception is run time error and java uses some techniques to handle the run time abnormality. These techniques are known as exception handling.

     12. What are different techniques of exception handling

There are four techniques of exception handling in java and these are throws, try catch, throw and try finally.

    13. Comparison among three loops

For loop
While loop
Do while loop
Entry control loop
Entry control loop
Exit control loop
Control statement contains three statements, initialisation, conditional statement and reinitialisation of loop control variable
Control statement contains only conditional statement while initialisation of loop control variable is done above the loop and reinitialisation of loop control variable is done within the loop body, normally at the end.
Control statement contains only conditional statement while initialisation of loop control variable is done above the loop body or within the loop body during first iteration of the loop and in such case the same statement performs reinitialisation during other iteration excepting the first one.
Loop control variable is reinitialised by programmer
Loop control variable is normally reinitialised by user
Loop control variable is normally reinitialised by user
Loop may not execute even once if the condition is false
Loop may not execute even once if the condition is false
Loop will execute atleast once if the condition is false

    14. Different type of decision making statements

In java there are different decision making statements and they are – if, if  else, else if ladder, switch statement and conditional statement.

    15. Comparison between else if ladder and switch

Else if ladder
switch
else if ladder can work on all type of values even on objects.
switch can work only on int and char calues
Logical operators can be used in else if ladder
Logical operators can not be used in switch
Fall through situation does not arise in else if ladder
If break statement is not used at the end of case body, fall through situation occurs.
else is optional in else if
default is optional in switch




    16. What is Wrapper class

Wrapper classes are predefined class stored in java.lang package. Each primitive type has an equivalent Wrapper class. Wrapper classes are used to convert a primitive type value into it’s equivalent object. Some of the Wrapper classes are Integer, Double, Boolean etc.

     17. What are the OOPs principles


There are three OOPs principles – Encapsulation, Inheritance and Polymorphism.


      18.    What is infinite loop

In loop conditional statement is used to terminate the execution of the loop after certain time but if we set the condition to be true then it becomes infinite loop. In infinite loop, break statement is necessary to send the control out of loop body. Example of infinite loops:

for (::)
{
 Statements
If(condition)
break;
}
while (true)
{
 Statements
If(condition)
break;
}
do
{
 Statements
If(condition)
break;
}while(true);

     19.    Two types of Java programs


Java applet and stand alone application.

CHECK HERE FOR PREVIOUS POSTS

Google+ Followers

Subscribe via email

Enter your email address:

Delivered by FeedBurner