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: Cannot calculate. Please help me....

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Cannot calculate. Please help me....

    import java.util.*;

    public class testing

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

    int a;
    int b;
    int calculation;
    char symbol;
    Scanner input=new Scanner (System.in);
    System.out.println("Enter first integer = ");
    a=input.nextInt();
    System.out.println("Enter second integer = ");
    b=input.nextInt();
    System.out.println("Enter your choice (+,-,*,/)");
    symbol=input.charAt(0);

    switch (symbol) {
    case '+' :
    calculation = a+b;
    System.out.printf("Addition is %d\n", calculation);
    break;
    case '-' :
    calculation = a-b;
    System.out.printf("Subtraction is %d\n", calculation);
    break;
    case '*' :
    calculation = a*b;
    System.out.printf("Multiply is %d\n",calculation);
    break;
    case '/' :
    calculation = a/b;
    System.out.printf("Division is %d\n", calculation);
    break;
    default :
    System.out.printf("Enter valid value = ");

    }

    }
    }


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Cannot calculate. Please help me....

    Do you have a specific question? Does it compile? Do you receive errors? You need to to give us as much information as possible, or else you make it more difficult to answer, and the more difficult it is to answer the less of a chance you will have in receiving an answer. Lastly, please wrap you code using the [highlight=java][/highlight] tags
    Last edited by copeg; September 15th, 2011 at 01:26 PM.

  3. #3
    Junior Member
    Join Date
    Sep 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Cannot calculate. Please help me....

    import java.util.*;

    public class testing

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

    int a;
    int b;
    int calculation;
    char symbol;
    Scanner input=new Scanner (System.in);
    System.out.println("Enter first integer = ");
    a=input.nextInt();
    System.out.println("Enter second integer = ");
    b=input.nextInt();
    System.out.println("Enter your choice (+,-,*,/)");
    symbol=input.charAt();

    switch (symbol) {
    case '+' :
    calculation = a+b;
    System.out.printf("Addition is %d\n", calculation);
    break;
    case '-' :
    calculation = a-b;
    System.out.printf("Subtraction is %d\n", calculation);
    break;
    case '*' :
    calculation = a*b;
    System.out.printf("Multiply is %d\n",calculation);
    break;
    case '/' :
    calculation = a/b;
    System.out.printf("Division is %d\n", calculation);
    break;
    default :
    System.out.printf("Enter valid value = ");

    }

    }
    }


    Sorry. It my first post to this website. Actually, I wanted to make calculator. When I wanted to compile my it get error like this:-

    found : int
    required: char
    symbol=input.nextInt();
    ^
    1 error

    I knows there is an error in my coding. It just i don`t how to make correction of my coding. Please help. Beside i`m just begin to learn java recently.

Similar Threads

  1. Calculate Button Not Working
    By czerenborg in forum AWT / Java Swing
    Replies: 8
    Last Post: September 8th, 2011, 09:25 PM
  2. I trying to calculate total price.
    By Muhanguzi in forum JDBC & Databases
    Replies: 6
    Last Post: June 15th, 2011, 03:35 PM
  3. GUI - calculate BMI (need help asap)
    By jahead in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 18th, 2011, 04:10 AM
  4. Calculate federal taxes program! Help!
    By ocmjt in forum What's Wrong With My Code?
    Replies: 13
    Last Post: March 11th, 2010, 11:25 AM
  5. Calculate primes help
    By TommyFiz in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 27th, 2009, 11:41 PM