Senin, 18 April 2011

concept calculator in java

This is the concept of making a simple calculator, in this concept is actually very easy. Here I make in java programming language. concepts that I use is read data values, then there is the selection of operators, in every operator there is a formula that is in use, such as the example x, the operator x are input b, and continued with the formula result = result * b, I write the results as input a equated with the results, and peoses will repeat continuously until the results get an e value.

public class calculator{
      private double a,b,hasil,i;
      private char op;
      public double hitung(){
                   
                    a=Input.readDouble();
                    hasil=a;
                    while(hasil !='p'){
                    op=Input.readChar();
                    if(op =='x'){
                              b=Input.readDouble();
                              hasil=hasil*b;}
                    else if(op=='/'){
                                     b=Input.readDouble();
                                     hasil=hasil/b;}
                    else if(op=='+'){
                                     b=Input.readDouble();
                                     hasil=hasil+b;}
                    else if(op=='-'){
                                     b=Input.readDouble();
                                     hasil=hasil-b;}
                   
                    else if(op=='!'){
                                      
                                       int g=1;
                                       for (i=2; i<=hasil; i++)
                                                 {g*= i;}
                                                 hasil=g;}
                    else if (op =='='){
                                   System.out.println(hasil+"\n");
                                   System.out.println("\n untuk exit tekan 1p: \n ");
                                   hasil=0;
                                   hasil=Input.readDouble();}
                    else if(op=='p'){hasil='p';}
                    else System.out.println("operator tidak ada \n");
                    }return 0;
}
public static void main()
{
calculator c=new calculator();
    c.hitung();
   
   
}
}
if you do not understand, please comment on this entry. if I find your problem, I will help you.

Tidak ada komentar:

Posting Komentar