Write a class to add two numbers

Hi guys,
Just trying to write a simple program that allows a user to input two numbers then get the result and display it. Im getting 3 errors at the momment
one at total and the other two at keyboard.readInt, can anyone see anything obvioulsy wrong please
<java>
public class Add
public static void main (String [] args)
int number1;
int number2;
int total =0;
System.out.println("please input a number");
number1=Keyboard.readInt();
System.out.println("please input your second number");
number2=Keyboard.readInt();
total=number1 + number2;
System.out.println("the total is" (total));
</java>

I have a feeling you copied someone else's code and don't know how to use it. You don't want to use readInt(). That's described in the DataInput Interface as "Reads four input bytes and returns an int value". What you want is a BufferedReader.
BufferedReader Keyboard = new BufferedReader(new InputStreamReader(System.in));
then,
String line = Keyboard.readLine();
int numberA = Integer.parseInt(line);

Similar Messages

  • X Control Add two numbers

    How do you have a Xcontrol with two numerical controls and add the numbers together and return them on the data output.
    I created the two numerical controls, put them in an event for when they change, and write the output to the data and have it be passed as a variable to my program.
    I can get the two numbers to add, update an indicator on the xcontrol front pannel, but it won't write to the data output! The output just reads 0!!!
    What setting am I missing?

    Did you set the "Data Changed" boolean to true
    CLA, LabVIEW Versions 2010-2013

  • How to Add two numbers using RFC in WD abap

    Dear Experts,
    I have to add the two numbers using RFC.
    I have created the RFC and by using create -> service call i have include that RFC in my WD abap Program.. After that i don't know how to link the input view and to display the result in another view...
    Please help me..
    Thank you.

    This is the third thread that you have posted on this same question.  This is also your second warning that such activity is not allowed in the SCN forums.  Please return to your original thread if you wish to post a follow up question. 
    Beacause this is a duplicate thread it will be locked.

  • How to use TextField to add two numbers and show the result.

    hi everybody
    i would like to use JTextField to get addtion of two Numbers,
    for example i am trying to type any integer numbers in JTextField like 7
    and press JButton, called( +) to add anthor number like 7 and press JButton called(=) to get addtion fo
    7 + 7 = 14, at same JTextField.
    so there will be two buttons, one for (+),other for (=).
    i have implement ActionListener in (+) button ,to get Text from JTextField (with getText() method),
    now how do i use same getText() method to get the next number that i will add it with previous number in
    (+) button and get the result whenever i press (=).
    1-type integer number like (4) in TextField.
    2-press addition button(+) to get text by using getText() method and clear TextField.
    3-type anthor integer number like(6).
    4-press (=) button to get the number (6) by using getText() method, calculate 4 + 6 and show the result at same TextField (10).
    i hope it is so clear
    thank u in advance for any advice and suggestion.

    Use your first button to
    String x = JTField.getText();
    int y = Integer.parseInt(x);
    this will get your first value on your + button. Make sure you initialise the int beforehand incase nothing is put in (ie error prevention) then clear the JTField prob using setText(""). Repeat the process for the = button using different variables and add them normally and output the result.
    If your putting more than 1 arithmetic button on the GUI then you'll need to distinguish between them!!!

  • Not yet able to add two integers using JSP

    I have written the following code for adding two integers. Its not working. I am getting 0 as the answer intead of 30. Can somebody help me with it?
    Zulfi
    <%
    String str1="0";
    String str2="0";
    int num3=0;
    int num4=0;
    int result=0;
    %>
    <FORM>
    <input name="num1" type="text" value="10" size="30">
    <input name="num2" type="text" value="20" size="30">
    <%
    str1=request.getParameter("num1");
    str2=request.getParameter("num2");
    if(str1==null) str1="0";
    if(str2==null) str2="0";
    num3 = Integer.parseInt(str1);
    num4 = Integer.parseInt(str2);
    result = num3+ num4;
    %>
    <input name="num3" type="text" value="<%= result %>">
    </FORM>

    <html>
    <head>
    <title>
    Solution
    </title>
    </head>
    <%
    String str1="0";
    String str2="0";
    int num3=0;
    int num4=0;
    int result=0;
    %>
    <body>
    <h1>
    Adds two Numbers
    </h1>
    <form method="post">
    <br><br>
    <input name="num1" type="text" value="10" size="30"><br>
    <input name="num2" type="text" value="20" size="30"><br>
    <input type="submit" name="Submit" value="Submit">
    <input type="reset" value="Reset">
    </form>
    </body>
    </html>
    <%
    str1=request.getParameter("num1");
    str2=request.getParameter("num2");
    if(str1==null) str1="0";
    if(str2==null) str2="0";
    num3 = Integer.parseInt(str1);
    num4 = Integer.parseInt(str2);
    result = num3+ num4;
    %>
    <input name="num3" type="text" value="<%= result %>">
    Good Luck

  • How do I add two cells in Numbers

    I know the answer must be really simple, but so far I cannot manage to do a simple calculations.
    All I want to do is add figures from two seperate cells E30 and E31. Each of these cells have the sub totals of cells above, and I just want to have the grand total by adding the numbers in both of the above cells.
    Thanks

    Darrell,
    Berfore we jump to the answer, please allow me to give you the most important suggestion I can: Read the first four chapters of the Numbers User Guide. It's free and can be downloaded from a link in the Help menu. Once you have downloaded it, Save it to your Desktop so it's handy.
    All calculations begin with the equal sign: =
    That signals Numbers that what follows is an expression that must be evaluated. To add two cells, write:
    =Cell1 + Cell2, where Cell1 and Cell2 are cell addresses such as D1 or F2.
    This expression is placed in the cell where you want the answer to appear.
    Jerry

  • Can Pages write two numbers one over another, like atomic number and mass?

    Is it possible in Pages 08 to write two numbers right atop one another like you do for atomic number and mass number? One a bit under the line, one a little over the line, both at the same place (not one after the other)? I haven't found out how to to it.
    TIA

    Perl,
    I'm a little hesitant to post this because it's so clunky, but I don't know how desperate you are to include this notation in your work so I'll throw it out there.
    You may create a Text Box with one number over the other and insert it into your work, but it comes with a big warning. Here's an example:
    Note the following:
    o The Text Box is formatted as Floating and Object Causes Wrap is UnChecked. Warning: If you add or delete text ahead of the symbol, the registration will be lost, and if you reformat the document in any way, you may have to go looking for your symbol and move it back to where it belongs.
    o The Text in the Box is formatted as Centered
    o You will have to manually create space for the symbol in your text by using spaces, changes in line spacing or other techniques.
    This notation is pretty rare, since the Atomic Number is redundant with the Element Symbol.
    Regarding a math module, you can create an impressive variety of math notations with Grapher.app, located in your Applications > Utilities folder. When you Copy and Paste notations from Grapher, you'll have the same problems with registration, unfortunately.
    Regards,
    Jerry

  • How to add two different page numbers in a single page

    How to add two different page numbers in a single page? One is for page number of the whole article, the other one is for page number for each chapter in the article.

    It's quite complicated, see
    Two Page Numbering Schemes in the Same Document.
    Regards, Hans Vogelaar (http://www.eileenslounge.com)

  • How do I add more than two numbers in a single cell

    I am wanting to add more than two numbers/values in a single cell.

    A1 = B1+C1+D1
    OR
    A1 = SUM(B1:D1)
    this is exactly summing three cells but may be extended to any number of cells up to the limit of the Numbers application

  • How to write a class for this?

    how do i write a different class for this? how do i implement the "a.add(b)"? it code is to test basic arithmetic operations.
              System.out.print ("Arithmetic: enter two integer numbers: ");
              Integer a = new Integer (Integer.parseInt(kbd.readLine()));
              Integer b = new Integer (Integer.parseInt(kbd.readLine()));
              System.out.println (a + "+" + b + "-" + b + "*" + a + "/" + a + "%" + b + " is: "                                    + a.add(b).sub(b).mul(a).div(a).rem(b));                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    public class arthOperation{
         add()
              sub()
         sub(){
              mul()
         mul(){
              div()
         div(){
              rem()
         rem(){
    is it write?

  • I have two numbers on one skype account - how do I...

    My skype account has two numbers and I want to add one more, how do I allow answering of them separately?

    Hi, DHPE.Staff, and welcome to the Community,
    Unfortunately, Skype does not provide a facility to do this.  While a Skype account's incoming calls, whether to the Skype account itself or a Skype Number, can be forwarded to multiple mobile or land line numbers, each Skype Number purchased for an account is considered affiliated with that account and cannot be forwarded separately.
    The work-around people use is to create a new account for each Skype Number needed; that way call forwarding and caller ID can be differentiated between the numbers.
    The thing to be mindful of in doing this, however, is to use different payment methods, otherwise the payment methods and accounts may be trapped inadvertently by Skype's anti-fraud filters.  More details about this here:
    https://support.skype.com/en/faq/FA4081/can-i-use-my-credit-card-to-fund-more-than-one-skype-account
    Regards,
    Elaine
    Was your question answered? Please click on the Accept as a Solution link so everyone can quickly find what works! Like a post or want to say, "Thank You" - ?? Click on the Kudos button!
    Trustworthy information: Brian Krebs: 3 Basic Rules for Online Safety and Consumer Reports: Guide to Internet Security Online Safety Tip: Change your passwords often!

  • ? how to add page numbers in pages 5.2, starting with 2.  Pages '09 had an option to not show folio on page one.  Also any how to do left and right folios for a Tabloid?  Many trhanks

    ? how to add page numbers in pages 5.2, starting with page 2.  Pages '09 had an option to not show folio on page one.  Also any idea how to do left and right folios for a Tabloid?  Many thanks  . . .

    Hello jacquemac,
    Your first question:
    There might be a better way of achieving what you wish to do, but following these steps could help you out.
    You might want to blend in Thumbnails and Invisibles either with (cmd+shift+i and cmd+alt+p) or over the View section in the Menubar.
    1. go for Documents (right end of the Toolbar) -> Section
    2. place your cursor at the very top of your second page and click "Create new Section->Starting with this page" in the side bar on your right.
    (what you are actually doing next is setting the pagenumbers for each section you created. You can see your sections in the Thumbnail view.)
    3. click on your first page (the first and only page of your first section) and mark the checkbox "Hide on first page of section"
    4. click on your second page (the first page of your second section) and  "Insert page number" -> start at 1
    Your second question:
    Im not quite sure i understand what exactly you want to do here. One page, two columns, each column with another page number? As far as i know this is not possible.
    greetings jl

  • I am using CC adobe Acrobat to combine multiple pdfs and add page numbers. Mac users can no longer read the page numbers but pc users can.

    I am using CC adobe Acrobat to combine multiple pdfs and add page numbers. As of about 2 weeks ago the mac users can no longer read the page numbers they get a font error message and see only -- where the page information should be. The pc users do not have this same problem. When I replace our regular font (URW Grotesk) with a system font (Verdana) everyone is able to read the page numbers. This is a new issues, I have been creating these documents in the same way for years without a problem. I have been on hold and on and off calls for the last two hours, I keep getting hung up on once I find someone in adobe support to talk to!

    Hi KnoopL,
    Are the Mac users using Preview to view the pdfs or Adobe Reader?
    Regards,
    Rave

  • How to merge to frequencies together and play it? I have a program that outputs two numbers everytime and those numbers in Hz. I want to merge those two different frequencies and play the sound.

    Hi there
    I have a program that reads from a table done in excel and finds two numbers from the table(they're different all the time). Those numbers are represented in Hz. What I want now is how to merge those two numbers as frequencies and output them and hear them from the speaker as audio. I also have the part of hearing them done but I can't figure out a way to have it connected so that it doesn't matter which numbers come up, it'll update it accordinaly. I appreciate any helpers.
    Thanks a lot

    Then I'm not sure what you're doing, or what your definition of "add" is. Here is the example I posted, with Signal 1 at 250 Hz and Signal 2 at 500 Hz:
    Message Edited by smercurio_fc on 01-15-2009 03:46 PM
    Attachments:
    add freqs.png ‏25 KB
    add freqs.vi ‏123 KB

  • Difference between two numbers in percentage.

    Hi,
    How to find difference between 2 numbers in percentage.
    Is there any standard function module.
    For example. I m having two numbers.
    25 & 31. I want to find how many percentage 25 is different from 31.
    Thanks in advance.

    hi,
    manual coding would be like this,
    data: no1 type i,
            no2 type i,
            no1per type d,
            no2per type d,
            diff type d.
    no1per = no1 / 100.
    no2per = no2 / 100.
    if no1per >= no2per
    diff = no1per  - no2per.
    write:/10 '% diff of',no1,'and',no2,' is',diff.
    else.
    diff = no2per  - no1per.
    write:/10 '% diff of',no2,'and',no1,' is',diff.
    if helpful reward some points.
    with regards,
    Suresh Aluri.

Maybe you are looking for