Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Need help with Addition Calculator!

  1. #1
    Laon8orsSon is offline Member
    Join Date
    May 2012
    Rep Power

    Question Need help with Addition Calculator!

    Im trying to make it so that you can input 2 numbers and they get added together then outputed to the screen! Help Please!
    It doesnt work like this because of the following:
    Cannot convert String to int

    Java Code:
    import java.util.Scanner;
    public class scannerTest {
    	public static void main(String[] args) {
    	Scanner in = new Scanner(;
    	System.out.println("What is your name?");
    	String name =;
    	System.out.println("Hello " + name + ", what two numbers");
    	System.out.println("would you like to add together?");
    	System.out.println("Number One?");
    	int numbOne =;
    	System.out.println("Number one is " + numbOne + ".");
    	System.out.println("Number Two?");
    	int numbTwo =;
    	System.out.println("Number two is " + numbTwo + ".");
    	float sum = numbOne + numbTwo;
    	System.out.println ("Number one plus number two equals " + sum + "!");
    Last edited by Laon8orsSon; 05-24-2012 at 04:54 AM.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Rep Power

    Default Re: Need help with Addition Calculator!

    What is your problem? Errors, incorrect output, code causes a block hole? We don't read minds.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power

    Default Re: Need help with Addition Calculator!

    Cannot convert String to int
    It's a good idea to say what line the compiler message refers to as we are very lazy here!

    Java Code:
    int numbOne =;
    Have a look at the API documentation for next(). Do you see that it returns a String? That's what the compiler is complaining about: you take this String and attempt to assign it to an int (numbOne). Look for a more appropriate method.

  4. #4
    j0rdan is offline Member
    Join Date
    Apr 2012
    Rep Power

    Default Re: Need help with Addition Calculator!

    As above; refer to a string were you would like a int input so if you look on that page you will see you made an easy mistake, in.nextInt(); should be used so the numbers are input as a int not a string.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Need help with Addition Calculator!

    j0rdan, don't spoonfeed. The guidance already given by pbrockway2 was adequate for Laon8orsSon to find that method by himself.

    Spoonfeeding denies questioners the opportunity to learn and mature toward solving their own problems (and hopefully helping others thereafter).

    quad64bit likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 9
    Last Post: 02-06-2012, 07:11 AM
  2. layout addition
    By droidus in forum Android
    Replies: 0
    Last Post: 11-17-2011, 09:08 PM
  3. addition
    By rithish in forum New To Java
    Replies: 4
    Last Post: 10-04-2011, 09:15 AM
  4. Addition of Two time
    By jithan in forum New To Java
    Replies: 5
    Last Post: 12-29-2008, 12:09 PM
  5. Addition Problem
    By tornado in forum New To Java
    Replies: 6
    Last Post: 12-07-2008, 12:37 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