Monday, December 24, 2012

STAR PRINTING 6 IN C++


#include<iostream.h>
void main()
{
 int i,j,k,n;
 cout<<"\Enter the number of lines to be printed: ";
 cin>>n;
 for(i=0;i<n;i++)
 {
       for(j=n-i-1;j>0;j--)
       cout<<" ";
       cout<<"*";
       for(k=2*i-1;k>0;k--)
       cout<<" ";          
       if(i!=0)
       cout<<"*";
       cout<<endl;
  }
  for(i=n-1;i>0;i--)
  {
       for(j=0;j<n-i;j++)
       cout<<" ";
cout<<"*";
 for(k=2*i-3;k>0;k--)
      cout<<" ";
       if(i!=1)
       cout<<"*";
       cout<<"\n";
    }
}
/*
OUTPUT
*/



STAR PRINTING 5 IN C++


#include<iostream.h>
void main()
{
    int i,j,n,k;
    cout<<"\Enter the number of lines to be printed: ";
    cin>>n;
    for(i=0;i<n;i++)
    {
       for(j=0;j<n-i;j++)
       {
    cout<<"*";
       }
       for(k=0;k<(2*n-2*j);k++)
       {
      cout<<" ";     //for spaces
       }
      for(j=0;j<n-i;j++)
       {
    cout<<"*";
       }
       cout<<"\n";
    }
}

DIAMOND SHAPE STAR PRINTING IN C++


#include <iostream.h>
void main()
{
int i,j,k;
for( i = 10; i >= 1; i-- )
{
for( j = 1; j < i; j++ )
{
cout << " ";
}
for( k=10; k >= j*2; k-- )
{
cout << "*";
}
cout << "\n";
}
for( i = 2; i <= 10; i++ )
{
cout << " ";
for( j = 2; j < i; j++ )
{
cout << " ";
}
for( k = 10; k >= j * 2; k-- )
{
cout << "*";
}
cout << "\n";
}
}

Wednesday, December 19, 2012

FIND A CHARACTER POSITION AND INDEX OF A STRING IN C++


#include<iostream.h>
void main()
{
int findpos(char s[],char c);
char string[80],ch;
int y=0;
cout<<"\nENTER MAIN STRING :\n";
cin.getline(string, 80);
cout<<"\nENTER CHARACTER TO BE SEARCH FOR : ";
cin.get(ch);
y=findpos(string,ch);
if(y==-1)
cout<<"\nSORRY!! THE CHARACTER IS NOT IN STRING.";
}
int findpos(char s[], char c)
{
int flag=-1;
for(int i=0; s[i]!='\0';i++)
{
if(s[i]==c)
{
flag=0;
cout<<"\nTHE CHARACTER IN THE STRING IS AT INDEX IS  : "<<i;
cout<<"\nTHE CHARACTER IN THE STRING IS AT POSITION : "<<++i;

}
 }
return (flag);
}

CONCATENATE TWO STRINGS PROGRAMME IN C++


#include<iostream.h>
#include<string.h>
void main()
{
char str1[50], str2[50], str3[100];
int count1, count2;
cout<<"ENTER THE FIRST STRING : ";
cin.getline(str1, 25);
cout<<"ENTER THE SECOND STRING : ";
cin.getline(str2, 25);
for(count1=0; str1[count1]!='\0'; count1++)
{
str3[count1]=str1[count1];
}
str3[count1]=' ';
count1++;
for(count2=0; str2[count2]!='\0'; count2++)
{
str3[count1+count2]=str2[count2];
}
str3[count1+count2]='\0';
cout<<"\nTHE NEW CONCATENATED STRING IS : \n\n";
cout<<str3;
}

STRING C++


#include<iostream.h>
#include<string.h>
void main()
{
char  ch, str[70], flag;
int len, count;
cout<<"\nENTER THE STRING:\n\n";
cin.getline(str, 70);
len=strlen(str);
cout<<"\nENTER A CHARACTER: ";
cin.get(ch);
flag='n';
for(count=0;str[count]!=len;count++)
{
if(ch==str[count])
{
flag='Y';
break;
}
}
if(flag=='Y')
{
cout<<"\n";
cout.put(ch);
cout<<" is contained in the string : \n\n";
cout.write(str,len);
}
else
{
cout<<"\n";

cout.put(ch);
cout<<" is not contained in the string : \n\n";
cout.write(str,len);
}
}

Tuesday, December 18, 2012

CONVERT A STRING TO UPPERCASE IN C++


#include<iostream.h>
#include<ctype.h>
#include<string.h>
void main()
{
char str[50];
int flag=1;
cout<<"\nENTER A STRING : \n\n";
cin.getline(str,50);
for(int i=0; str[i]!='\0';i++)
{
if(islower(str[i]))
{
flag=1;
str[i]=toupper(str[i]);
}
}
if((flag==1)||(str[i]=='\0'))
{
cout<<"\nUPPERCASE STRING IS :\n\n";
cout<<str;
}
}

FIND THE LARGEST AND SMALEST ELEMENT IN A VECTOR IN C++


 #include<iostream.h>
void main()
{
int count, num, vec[100], large, small;
cout<<"ENTER HOW MANY ELEMENTS ARE THERE IN THE VECTOR : ";
cin>>num;
cout<<"\nENTER THE VALUES IN THE VECOR \n";
for(count=0; count<num; count++)
cin>>vec[count];
large=small=vec[1];
for(count=0; count<num;count++)
{
if(vec[count]>large)
large=vec[count];
else if(vec[count]<small)
small=vec[count];
}
cout<<"\nTHE LARGEST ELEMENT IS : "<<large<<endl;
cout<<"\nTHE SMALLEST ELEMENT IS : "<<small<<endl;
}


THE FACTORS OF THE NUMBER IN C++


#include<iostream.h>
void main ()
{
int num, fact, gfact;
cout<<"ENTER A NUMBER : ";
cin >> num;
gfact=num/2;
cout<<"THE FACTORS OF " << num << " ARE : " << endl;
for ( fact=1; fact<=gfact; fact=fact+1)
{
if (num%fact==0)
cout << fact << endl;
}
}

FIBONACCI SERIES 3 PROGRAMME IN C++


#include<iostream.h>
void main()
{
int a=0,b=1,c=0,n;
cout<<"Enter the number of element required: ";
cin>>n;
cout<<a<<" "<<b<<" ";
for(int i=1;i<=n-2;i++)
{
c=a+b;
a=b;
b=c;
cout<<c<<" ";
}
}

FIBONACCI NUMBER SERIES PROGRAMME 2 IN C++


#include <iostream.h>
int fib(int n)
{
  if(1 == n || 2 == n)
  {
      return 1;
  }
  else
  {
      return fib(n-1) + fib(n-2);
  }
 }
void main()
{
    for(int i=1; i<=10; i++)
    {
        cout << fib(i) << endl;
    }
}

FIBONACCI NUMBER PROGRAMME IN C++


#include<iostream.h>
void main()
{
char choice;
do
{
long double num, a=1, b=0, count;
cout<<"ENTER THE NUMBER OF ELEMENTS REQUIRED : ";
cin>>num;
cout<<"\n\n";
for(count=1; count<=num/2;count++)
{
a+=b;
cout<<b << "\t";
b+=a;
cout<<a << "\t";
}
cin>>choice;
}while(choice=='x'||choice=='x');
}

Monday, December 17, 2012

PRIME NUMBER PROGRAMME IN C++


#include<iostream.h>
void main ()
{
long num, fact; int count;
cout << "ENTER A NUMBER : ";
cin >> num;
for ( fact=1, count=0; fact<=num/2; fact=fact+1)
{
if (num%fact==0)
count=count+1;
}
if (count==1)
cout << "\nYES! IT IS A PRIME NUMBER." << endl;
else
cout << "\nNO! IT IS NOT A PRIME NUMBER." << endl;
}

PERFECT NUMBER PROGRAMME IN C++


#include<iostream.h>
void main ()
{
int num, fact, gfact, fsum=0;
cout << "ENTER A NUMBER : ";
cin >> num;
gfact=(num/2)+1;
for (fact=1; fact<=gfact; fact=fact+1)
{
if (num%fact==0)
fsum+=fact;
}
if (fsum==num)
cout << "\nIT IS A PERFECT NUMBER. " << endl;
else
cout << "\nIT IS NOT A PERFECT NUMBER. " << endl;
}

STAR PRINTING 4 IN C++


#include<iostream.h>
void main()
{
int count,i, n=10;
for(count=0;count<=n;count++)
{
for(i=0; i<count;i++)
{
cout<<" ";
}
for(int j=10; j>count;j--)
{
cout<<"*";
}
cout<<endl;
}
}

/*
OUTPUT
*/

STAR PRINTING 3 IN C++


#include<iostream.h>
void main()
{
int count,i, n=10;
for(count=0;count<=n;count++)
{
for(int j=10; j>count;j--)
{
cout<<" ";
}
for(i=0; i<count;i++)
{
cout<<"*";
}
cout<<endl;
}
}
/*
output
*/

STAR PRINTING 2 IN C++


#include<iostream.h>
void main()
{
int count,i;
for(count=10;count>=0;count--)
{
for(i=count;i>=0;i--)
cout<<'*';
cout<<endl;
}
}
 /*OUTPUT
*/







STAR PRINTING 1 IN C++


#include<iostream.h>
void main()
{
int count,i;

for(count=0;count<=10;count++)
{
for(i=0;i<=count;i++)
cout<<'*';
cout<<endl;
}
}

/*
OUTPUT
*/

EXAMPLE CODING OF INCREMENT AND DECREMENT OPERATORS IN C++


#include<iostream.h>
void main()
{
int num, a,b,c,d;
cout<<"ENTER A NUMBER : ";
cin>>num;
a=num;
b=num;
c=num;
d=num;
cout<<"\n"<<num<<" is assigned to a,b,c and d : "<<endl;
cout<<"++a = " << ++a<<"\n--b = "<< --b<<"\nc++ = " << c++<<endl;
cout<<"d-- = " << d--<<endl;
cout<<"a = "<<a<<"\nb = "<<b<<"\nc = "<<c<<"\nd = "<<d<<endl;
}

GREATER OF THREE NUMBERS IN C++


#include<iostream.h>
void main()
{
int a, b, c;
cout<<"ENTER THE FIRST NUMBER : ";
cin>>a;
cout<<"ENTER THE SECOND NUMBER : ";
cin>>b;
cout<<"ENTER THE THIRD NUMBER : ";
cin>>c;
if(a>b && a>c && b>c)
{
cout<<a<<" IS GREATEST."<<endl;
cout<<b<<" IS SECOND GREATEST."<<endl;
cout<<c<<" IS LEAST.";
}
else if(a>b && a>c && c>b)
{
cout<<a<<" IS GREATEST."<<endl;
cout<<c<<" IS SECOND GREATEST."<<endl;
cout<<b<<" IS LEAST.";
}
else if(b>a && b>c && a>c)
{
cout<<b<<" IS GREATEST."<<endl;
cout<<a<<" IS SECOND GREATEST."<<endl;
cout<<c<<" IS LEAST.";
}
else if(a>b && a>c && c>a)
{
cout<<b<<" IS GREATEST."<<endl;
cout<<c<<" IS SECOND GREATEST."<<endl;
cout<<a<<" IS LEAST.";
}
else if(c>a && c>b && b>a)
{
cout<<c<<" IS GREATEST."<<endl;
cout<<b<<" IS SECOND GREATEST."<<endl;
cout<<a<<" IS LEAST.";
}
else if(c>a && c>b && a>b)
{
cout<<c<<" IS GREATEST."<<endl;
cout<<a<<" IS SECOND GREATEST."<<endl;
cout<<b<<" IS LEAST.";
}
else
cout<<"INVALID INPUT.";
}

SQUARE OF A NUMBER IN C++


#include<iostream.h>
void main ()
{
int num, sqr;
cout << "ENTER THE NUMBER : ";
cin >> num;
sqr= num*num;
cout << "\nTHE SQUARE OF " << num << " is " << sqr;
}

Sunday, December 16, 2012

FIND THE BIG NUMBER OF TWO NUMBERS IN C++


#include<iostream.h>
void main()
{
int num1, num2;
cout << "PLEASE ENTER THE FIRST NUMBER : ";
cin >> num1;
cout << "PLEASE ENTER THE SECOND NUMBER : ";
cin >> num2;
if (num1>num2)
{
cout << "1st NUMBER IS GREATER THAN 2nd NUMBER.";
}
else
{
cout << "2nd NUMBER IS GREATER THAN 1st NUMBER.";
}
}

SWAPPING NUMBERS IN C++


#include<iostream.h>
void main()
{
int a, b, c;
cout<<"\nENTER FIRST NUMBER : ";
cin>>a;
cout<<"\nENTER SECOND NUMBER : ";
cin>>b;
c=a;
a=b;
b=c;
cout<<"\nNEW FIRST NUMBER= "<<a;
cout<<"\nNEW SECOND NUMBER= "<<b;
}

MULTIPLICATION OF TWO NUMBERS IN C++


#include<iostream.h>
void main()
{
int no1,no2,m;
cout<<"ENTER THE FIRST NUMBER : ";
cin>> no1;
cout<<"\nENTER THE SECOND NUMBER : ";
cin>>no2;
m=no1*no2;
cout<<"\nTHE DIFFERENCE OF TWO NUMBERS IS : "<<m;
}

FIND THE DIFFERENCE BETWEEN TWO NUMBERS IN C++


#include<iostream.h>
void main()
{
int no1,no2,d;
cout<<"ENTER THE FIRST NUMBER : ";
cin>> no1;
cout<<"\nENTER THE SECOND NUMBER : ";
cin>>no2;
d=no1-no2;
cout<<"\nTHE DIFFERENCE OF TWO NUMBERS IS : "<<d;
}

FIND THE SUM OF THE TWO NUMBERS IN C++


#include<iostream.h>
void main ()
{
int no1,no2,sum;
cout<<"ENTER FIRST NUMBER : ";
cin>>no1;
cout<<"ENTER SECOND NUMBER :";
cin>>no2;
sum=no1+no2;
cout<<"THE SUM OF TWO NUMBER : "<<sum;
}








Friday, December 7, 2012

Data Structures and Algorithms with Java - 1 PAST PAPER 2008


1.

(a.) Specify the most suitable data type to declare followings? [3 Marks]
       i.) No of subjects in the course
      ii.) Name of the lecturer
     iii.) Average mark for a subject in a class

(b.) List all primitive data types [4 Marks]

(c.) Explain the purpose of following escape sequence characters? [3 Marks]
                 i.) \n
                ii.) \t
               iii.) \”
(d.) What will be the output of following program fragment? [2 Marks]
            byte num=0;
                 num++;
                 ++num;
             System.out.println(num++);

(e.) Fill in the blanks of the following sentences with suitable terms. [4 Marks]
    i.) The file produced by the java compiler contains………………..that are executed by the Java Virtual                               Machine.
   ii.) Three parts in the method definition form …………………………...
  iii.) A variable declared and initiated within a loop is known as …………
  iv.) A class variable should be declared with a…………keyword before the type of variable.

(f.) Write a java program to compare two integer variables and display the largest
using with input and message dialog boxes. [4 Marks]

2.

(a.) State whether each of the following is true or false. [4 Marks]
   i.) By convention, method names begin with an uppercase first letter and all subsequent words in the name   begin with a capital first letter
  ii.) Empty parentheses following a method name in a method declaration indicate that the method does not require any parameter to perform its task.
  iii.) The number of argument in the method call must match the number of parameters in the method declaration’s parameter list.
 iv.) An import declaration is not required when one class in a package uses another in the same package.

(b.) What is the different between local variable and a field? [2 Marks]

(c.) Explain the purpose of a method parameter. What is the difference between a
parameter and an argument? [2 Marks]

(d.) Write a complete Java application to prompt the user for the double radius of a
sphere, and call method sphereVolume to calculate and display the volume of the sphere. Use the Math.pow( radius) method and Math.PI constant of Math class. [4 Marks]

(e.) Write what would be the output of the following program if it is executed. [8 Marks]
    class ResultPrint
      {
          public static void main(String[] args)
             {
              int x1 = 5, x2 = 6, x3 = 4, x4 = 7;
              System.out.println((x1^2+3*x3)/2);
              System.out.println( x1 == 5);
              System.out.println( x2!=6 );
               System.out.println( x3!= 5 && x4 < 8);
              System.out.println( x1<= 3 & x2 > x3);
             System.out.println( x2 >= x3|| x1 != x4);
             System.out.println( x1 + x2 - x3> x4 | 4*x1>= (x3^2));
              System.out.println( x4 != x3+x2 );
            }
  }

3.

(a.) After compilation of program files, following error messages were shown on
command prompt. Identify the causes for those specific errors. [4 Marks]
                    i.) Testing.java:8:package system does not exist.
                          system.out.println(“No of items:”+totalItem);
                                   ^
                                 1 error

                    ii.) Testing.java:10: cannot find symbol
                                   Location: class Testing
                                    Symbol: variable count
                                        ++count;
                                         ^
                                2 errors

(b.) Find the error in each of the following code segment and explain how to
correct it. [4 Marks]
           i.) For(index =0.1;index!=1.0;index+=0.1)
                   System.out.println(“Index =” + index);
           ii.) Switch(x)
                      {
                             case 1:
                             System.out.println(“The number is 1”);
                            Break;
                            case 2:
                           System.out.println(“The number is 2”);
                              Default:
                           System.out.println(“The number is not 1 or 2”);
                           Break;
                    }

(c.) Compare and contrast the while and for loop repetition statement [2 Marks]

(d.) Write the output if the following code is executed. [4 Marks]
                        class LabelTest
                                {
                                        public static void main (String arg[])
                                              {
                                                      xyz:
                                                     for (int i = 1; i <= 4; i++)
                                                          for (int j = 1; j <= 2; j++) {
                                                    System.out.println("i is " + i + ", j is " + j);
                                                    if (( i + j) > 3)
                                                      break xyz;
                                                     }
                                                 System.out.println("End of loops");
                                               }
                                     }
         (e.) What would be the output if the following code is executed ? [6 Marks]
class PatPrint
{
public static void main(String[] args)
{
for(int i=0;i<2;i++)
{
for(int j=0; j<1;j++)
System.out.print("*");
System.out.print("\n");
for(int j=0; j<2;j++)
System.out.print("*");
System.out.print("\n");
for(int j=0; j<3;j++)
System.out.print("*");
System.out.print("\n");
for(int j=0; j<4;j++)
System.out.print("*");
System.out.print("\n");
for(int j=0; j<5;j++)
System.out.print("*");
System.out.print("\n");
}
}

}      



4


(a.) Fill in the blanks in each of the following statements. [4 Marks]
                                i.) The ………………..statement in a called method can be used to pass the value of an expression back to the calling method.
ii.) An array that uses two indices is referred to as a(n)…………array.
iii.) The name of the element in row 3 and column 5 of array d is ………..
iv.) Command-line arguments are stored in …………………………..

(b.) Determine whether each of the following is true or false. [4 Marks]
i.) An array can store many different types of values.
ii.) An array index should normally be of type double.
iii.) Command-line arguments are separated by white space.
                                iv.) Expression array.length is used to access the number of arguments of a variable-length argument called array.

(c.) Perform the following tasks for an array called table: [3 Marks]
                           i.) Declare and create the array as an integer array has three rows and three columns. Assume that the constant ARRAY_SIZE has been declared to be 3.

ii.) How many elements does the array contain?
                                  iii.) Use a for statements to initialize each element of the array to the sum of its indices. Assume that the integer variable x and y are declared as control variable.

(d.) Write the output of the following program if it is executed. [4 Marks]
class FamilyList
{
String[] personNames = {"Mendis", "Ravi", "Nihar", "James"};
String[] personWifeNames = new String[personNames.length];
void printPersonNames()
{
for(int i = 0; i< personNames.length; i++)
{
System.out.println(personNames[i]);
}
}
void printPersonWifeNames()
{
for(int i = 0; i< personWifeNames.length; i++)
{
System.out.println(personWifeNames[i]+" "+ personNames[i]);
}
}
public static void main (String args[])
{
FamilyList familyList = new FamilyList();
System.out.println("List of Male");
System.out.println("-------------");
familyList.printPersonNames();
familyList.personWifeNames[0]= "Malathy";
familyList.personWifeNames[1]= "Priya";
familyList.personWifeNames[2]= "Susmina";
familyList.personWifeNames[3]= "Rosemary";
System.out.println();
System.out.println("List of Female");
System.out.println("---------------");
familyList.printPersonWifeNames();
}
}


(e.) Write method distance to calculate the distance between two points
(x1, y1) and (x2, y2). All numbers and return values should be of type double. Incorporate this method into an application that enables the user to enter the coordinates of the points. [5 Marks]

5.

(a.) Complete the following statements with suitable terms. [5 Marks]
                        i.) The ………… method is called by the garbage collector just before it reclaims an object’s memory.
ii.) Keyword …………specifies that a variable is not modifiable.
                    iii.) A(n)……………….consists of a data representation and the operations that can be performed on the data.
                   iv.) ……………………is a form of software reusability in which new classes acquire the member of existing classes and embellish those classes with new capabilities
                v.) A superclass’s …………members are accessible anywhere that the program has a reference to an object of that superclass or to an object of one of its subclass.
(b.) Define what the following terms means: [6 Marks]
i.) abstract class
ii.) concrete class
iii.) Interface
(c.) What will be the output if the following code is executed? [6 Marks]
class VariableScopeTest
{
static int num1 = 10;
int num2 = 15;
void printNumGroup1()
{
System.out.println("Number2 = " + num2);
}
public static void main (String args[])
{
System.out.println("Number1 = " + num1);
VariableScopeTest vST = new VariableScopeTest();
vST.printNumGroup1();
vST.printNumGroup2();
System.out.println("Number2 = " + vST.num2);
}
void printNumGroup2()
{
int num2 = 20;
7
System.out.println("Number2 = " + num2);
System.out.println("Number2 = " + this.num2);
}
}
(d.) Define class variable, instance variable and local variable. Give an example
from the source code given (c.). [3 Marks]

6.

(a.) What will be the output if the following code is executed? [5 Marks]
public class TestMathFun
{
public static void main(String [] args)
{
double val1 = 9.2;
double val2 = -23.3;
double val3 = -9.8;
System.out.printf("%s\t%s\t%s\t%s\t\n","value","abs","ceil","floor");
System.out.printf( "%.1f\t%.1f\t%.1f\t%.1f\t\n", val1,Math.abs(val1),Math.ceil(val1),Math.floor(val1));
System.out.printf( "%.1f\t%.1f\t%.1f\t%.1f\t\n", val2,Math.abs(val2),Math.ceil(val2),Math.floor(val2));
System.out.printf( "%.1f\t%.1f\t%.1f\t%.1f\t\n", val3,Math.abs(val3),Math.ceil(val3),Math.floor(val3));
}
}

(b.) List five common examples of exceptions. [2.5 Marks]

(c.) Give reasons why exception-handling techniques should not be used for
conventional program control. [2 Marks]

(d.) If no exceptions are thrown in try block, where does control proceed to when the
try block completes execution? [1.5 Marks]

(e.) What would be the output of the following source code if an integer numerator is
divided by a zero denominator? [5 Marks]
import java.util.Scanner;
public class TryCatchTest
{
public static int quotient( int numerator, int denominator )
8
{
return numerator / denominator;
}
public static void main( String args[] )
{
Scanner scanner = new Scanner( System.in );
boolean continueLoop = true;
do
{
try
{
System.out.print( "Enter an integer for numerator: " );
int numerator = scanner.nextInt();
System.out.print( "Enter an integer for denominator: " );
int denominator = scanner.nextInt();
int result = quotient( numerator, denominator );
System.out.printf( "\nResult: %d / %d = %d\n", numerator, denominator, result );
continueLoop = false;
}
catch ( ArithmeticException arithmeticException )
{
System.err.printf( "\nException: %s\n", arithmeticException );
System.out.println( "Zero is an invalid denominator. Please try again.\n" );
}
}while(continueLoop);
}
}

(f.) Define each of the following terms. [4 Marks]
i.) thread
ii.) multithreading
iii.) runnable state
iv.) timed waiting state

Saturday, December 1, 2012

JAVA Fundamental

Fundamentals


Java Terminology 

* Java Virtual Machine(JVM) –set of computer software programs and data structures that use a virtual machine model for the execution of other computer programs and scripts.
* Java Runtime Environment(JRE) –A runtime environment which implements Java Virtual Machine, and provides all class libraries and other facilities necessary to execute Java programs. This is the software on your computer that actually runs Java programs
* Java Development Kit(JDK) –The basic tools necessary to compile, document, and package Java programs (javac, javadoc, and jar, respectively). The JDK includes a complete JRE.
* Application Programming Interface (API) –Contains predefined classes and interfaces for developing Java programs

Comments 

Comment-The contents of a comment are ignored by the compiler.  Three type of comment in java.
1. Single line comments(Slash-Slash) //text // This comment extends to the end of the line.
2. Multiple line comments  /* This comment, a "slash-star" comment, includes multiple lines.*/ 
3. Documentation Comments /** documentation */  The last type of comment is the
Javadocument. This comment type has some guidelines that allows a Javadocreader to display information about a Java method or class by using special tags 

Excercise
# Exercise:Write a simple Java program which displays following two lines on the screen.
I like Java programming.
So I do practical .

Operators 

* An operator is a symbol that tells the compiler to perform a specific mathematical or logical manipulation.
* Java has four general classes of operators: arithmetic, bitwise, relational, and logical
* Examples of expressions that include Java operators :
 1. n = 2
 2. n += 3
 3. ++n
 4. n / 3
5.  n % 3




Arithmetic Operators












Example
x = y / 2;
* in the above expression, x and y are variables, 2 is a literal and = and / are operators. 
* This expression states that the y variable is divided by 2 using the division operator (/), and the *result is stored in x using the assignment operator (=).Notice the expression was described from right to left. 
*It is how the compiler itself analyzes expressions to generate code.








It is also possible to use the shortcuts for arithmetic operators as given below.










class Arithmetic {

public static void main (String args[]) 
{

intx=17, y=5;

System.out.println(“x=“+x);

System.out.println(“y=“+y);

System.out.println(“x+y=“+(x+y));

System.out.println(“x-y=“+(x-y));

System.out.println(“x*y=“+(x*y));

System.out.println(“x/y=“+(x/y));

System.out.println(“x%y=“+(x%y));

}

}
Output
 










 Bitwise Operators