Showing posts with label java operators. Show all posts
Showing posts with label java operators. Show all posts

Tuesday, August 31, 2010

Choose operators using if statement

hello programmers... this program will show to you how to use if statement. It is for computing two input numbers by the user. this is for asking the user to choose the operator they want to execute. 1- addition, 2- subtraction, 3- Multiplication, 4- Quotient. this is a very simple program using nested if statement.


here is a sample program:

import java.io.*;
import java.util.Scanner;

public class chooseoperators
{
public static void main(String args[])
{

Scanner input==new Scanner(System.in);
int add=1;
int sub=2;
int mult=3;
int div=4;
int num1;
int num2;
int oper;
int sum=0,diff=0,prod=0,quo=0;
System.out.println("1- Addition");
System.out.println("2- Subtraction");
System.out.println("3- Multiplication");
System.println("4- Division");

System.out.print("Enter First Number:");
num1=input.nextInt();

System.out.print("Enter Second Number:");
num2=input.nextInt();


System.out.print("Chooose Operators:");
oper=input.nextInt();


if(oper==add)
{
sum=num1+num2;
System.out.println("The sum is:" + sum);
}


if(oper==sub)
{
diff=num1-num2;
System.out.println("The difference is:" +diff);
}



if(oper==mult)
{
prod=num1*num2;
System.out.println("The Product is:" + prod);
}



if(oper==div)
{
quo=num1/num2;
System.out.println("The quotient is:" + quo);
}
}
}

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