Results 1 to 5 of 5
  1. #1
    Akar-Slemany is offline Member
    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Default Rate my app : Simple Calculator

    Here's a simple calculator that i made with java , i am very new java programming.

    Here's my code, i hope you like it.
    Java Code:
    import java.util.Scanner;
    
    
    public class Main {
    	
    	private static Scanner input; //define a private Scanner named input
    
    	public static void main ( String args[]){ 
    		
    		input = new Scanner(System.in);
    		 double fnum;//define first number
    		 double snum;// define second number;
    		 double answer; // define answer
    		
    		System.out.println("Please enter a number : "); // prompt user to enter first number.
    		fnum = input.nextDouble(); // store a number in fnum Scanner Variable
    		
    		System.out.println("Enter a second number :");//  prompt user to enter second number.
    		snum = input.nextDouble(); //store a number in snum Scanner Variable
    		
    		
    		answer = fnum + snum;
    		System.out.println("Plus : "+answer);
    		answer = fnum - snum;
    		System.out.println("Minus : "+answer);
    		answer = fnum * snum;
    		System.out.println("Multiply : "+answer);
    		answer = fnum / snum;
    		System.out.println("Divide = " + answer);
    		
    		
    	}
    
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default Re: Rate my app : Simple Calculator

    Type 0.0 for the second number and see ... then type utter nonsense for one or both of the numbers and see again ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Akar-Slemany is offline Member
    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Default Re: Rate my app : Simple Calculator

    Thanks for telling me that

    I cleared out that bug

    here's new one :

    Java Code:
    import java.util.Scanner;
     
     
    public class Main {
         
        private static Scanner input; //define a private Scanner named input
     
        public static void main ( String args[]){ 
             
            input = new Scanner(System.in);
             double fnum;//define first number
             double snum;// define second number;
             double answer; // define answer
             
            System.out.println("Please enter a number : "); // prompt user to enter first number.
            fnum = input.nextDouble(); // store a number in fnum Scanner Variable
             
            System.out.println("Enter a second number :");//  prompt user to enter second number.
            snum = input.nextDouble(); //store a number in snum Scanner Variable
            if (fnum == 0.0 && snum == 0.0  )
            {
            	System.out.println("Cannot Calculate two zeros");
            }
            
            else {
            	
           
         
             
            answer = fnum + snum;
            System.out.println("Plus : "+answer);
            answer = fnum - snum;
            System.out.println("Minus : "+answer);
            answer = fnum * snum;
            System.out.println("Multiply : "+answer);
            answer = fnum / snum;
            System.out.println("Divide = " + answer);
            }
            
          
             
             
        }
     
    }

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default Re: Rate my app : Simple Calculator

    But now your calculator can't do, say, 0+0; it should refuse to divide by zero only.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    CuppaCoffee's Avatar
    CuppaCoffee is offline Member
    Join Date
    Jan 2012
    Location
    Canada
    Posts
    80
    Rep Power
    0

    Default Re: Rate my app : Simple Calculator

    Why did you declare the scanner globally when you're only using it in one place?

Similar Threads

  1. Simple calculator
    By itaiyz97 in forum New To Java
    Replies: 2
    Last Post: 09-24-2012, 05:21 PM
  2. Help making a very simple calculator?
    By sfs in forum New To Java
    Replies: 2
    Last Post: 01-26-2012, 03:59 AM
  3. Trying to make simple calculator
    By Buldogg in forum New To Java
    Replies: 1
    Last Post: 09-18-2011, 01:37 PM
  4. Simple Calculator
    By marksey07 in forum New To Java
    Replies: 12
    Last Post: 01-09-2011, 06:30 AM
  5. creating a simple calculator
    By hobo in forum New To Java
    Replies: 4
    Last Post: 11-09-2009, 03:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •