Thursday, July 8, 2010

Relational Operators in programming

This operator used in programming to make a decision making. this operator is answer by true or false or yes or no only. the program execute depending on the result of operations.

These are the Relational Operators
>          greater than
>=       greater than or equal
<         less than
<=      less than or equal
==      equal
!=       not equal

Java Operators

Programming Operators are use in computing the numbers using programming.

here are the the operators used in programming.

   name         Symbols
1. Addition                    +
2. Subtraction               -
3. Multiplication          *
4. Division                    /
5. Modulo                   %           - this operator used to get the remainder

Escape sequence in programming

This are the common escape sequences in programming.

\n     - newline.
\t      - Horizontal Tab
\r     - Carriage return
\\     - Backslash
\"     - Double Quote

IF ELSE statement sample program

This program will compute the 3 grades and get the average. the program will show a message "Your Passed" if the average is 75 above. else the program will show a message " Your Failed" if the average is Below 75.

here is the program.

import java.io.*;

public class ComputeAverage
{
public static void main(String args[])
{
//declaration of variables
int math=90;
int PE=90;
int prog=95;
int ave=0;

//Compute the average

ave=(math + PE + prog)/3;

//display the average
System.out.print("Your average is:" + ave);


//checking the average if it is 75 above or below 75 using if statement

if(ave>=75)
{
System.out.print("Your Passed");
}
else
{
System.out.print("Your Failed");
}

}
}

IF ELSE sample program

This program will determine the age of person if 18 above  or 18 below. the program will show message " Your qualified to vote" if the age of person is 18 above, else the program will show message " Your not qualified to vote" if the age of person is 18 below.

here is the sample program.

import java.io.*;

public class SampleIf
{
public static void main(String args[])
{
//declaration
int age=18;

if(age>=18)
   {
     System.out.println("Your Qualified to Vote");
    }
else
   {
    System.out.print("Your not Qualified to vote");
   }
}

}