Saturday, September 12, 2015

Calculator using java

/*
* Write a C program for performing as calculator which allows all Arithmetic Operators with operands from
* terminal
 */
package cb_pr176;
import java.util.Scanner;
/**
 **
 * @author Arif
 **/
public class Cb_pr176 {
    /*
     * @param args the command line arguments
     */
    public static void main(String[] args) {
    // TODO code application logic here
    Scanner inp=new Scanner(System.in);
    int a,b;
    float c = 0;
    char ch;
    System.out.println("Enter Your 1st number:");
    a=inp.nextInt();
    System.out.println("Enter your 2nd number:");
    b=inp.nextInt();
    System.out.println("Enter your choice, example: +, -, *, /");
    ch=inp.next().charAt(0);
    if (ch=='+')
        c=a+b;
    else if(ch=='-')
        c=a-b;
    else if(ch=='/')
        c=(float)a/(float)b;
    else if(ch=='*')
        c=a*b;
    System.out.println("The Result is:" + c);
         
    }
  }

Calcualate Simple Interest using java

/*
*Write a C program to find the Simple Interest. Take input for principle amount, rate of interest and time
*from terminal.
*Simple Interest is the money paid by the borrower to the lender, based on the Principle Amount, Interest
*Rate and the Time Period.
*Simple Interest is calculated by, SI= P * T * R / 100 formula.
*Where, P is the Principle Amount.
*T is the Time Period.
*R is the Interest Rate.
*/
package cb_pr175;
import java.util.Scanner;

public class Cb_pr175 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner inp=new Scanner(System.in);
        int pa,ye;
        float rate,si;
        System.out.println("Enter your principal amount");
        pa=inp.nextInt();
        System.out.println("Enter your number of year");
        ye=inp.nextInt();
        System.out.println("Enter your rate of interest");
        rate=inp.nextFloat();
        si=(rate*pa)*ye;
        System.out.println("Your total interest is " + si);
       
    }

}