Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: simple basic calculator

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post simple basic calculator

    am trying to make a simple calculator but i really want something more than this ,here is my code :

    package revolution;

    import java.util.Scanner;


    public class simplecalculator {

    public static void main(String[] args){
    int x , y ,result = 0 ;
    char c;

    Scanner input = new Scanner(System.in);

    //gather user inputs

    System.out.print("ENTER NO.: ");
    x = input.nextInt();

    System.out.print("enter operator: ");
    String st = input.next();
    c = st.charAt(0);





    System.out.print("ENTER NO.: ");
    y = input.nextInt();


    switch(c){

    case'+':
    result = x + y;
    System.out.print("SUM: "+result);
    break;

    case'-':
    result = x - y ;
    System.out.print("DIFFERENCE: "+result);
    break;

    case '*':
    result = x*y;
    System.out.print("MULTIPLE: "+result);
    break;

    case '/':
    result = x/y;
    if(y == 0){
    System.out.print("ERRORIVISION BY ZERO");
    }else{

    System.out.print("DIVISION: "+result);

    }
    break;

    default:
    System.out.print("SYNTAX ERROR");







    }





    }




    }
    any one with much more better idea than this ..........would be happy to share


  2. #2
    Member
    Join Date
    Oct 2013
    Location
    Manila, Philippines
    Posts
    285
    My Mood
    Amused
    Thanks
    6
    Thanked 64 Times in 61 Posts

    Default Re: simple basic calculator

    try to do the process continuously, like after the first operation, ask again the user whether he/she wants to do another operation.

    or
    create a GUI for you calculator. that would be a challenging one

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: simple basic calculator

    Welcome to the Forum! Please read this topic to learn how to post code correctly and other useful tips for newcomers.

    Please post your code correctly.

Similar Threads

  1. Problem with basic calculator - Beginner
    By Dream Hacked in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 25th, 2013, 11:00 PM
  2. Simple Calculator
    By Spanky13 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 25th, 2013, 05:33 PM
  3. A basic calculator
    By SathApoc in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 22nd, 2011, 12:47 PM
  4. having bad time with basic calculator code
    By hashey100 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 12th, 2011, 09:29 PM
  5. Basic Calculator
    By Yes. in forum What's Wrong With My Code?
    Replies: 13
    Last Post: June 4th, 2010, 04:24 PM