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 10 of 10

Thread: INT Operations Help Plz

  1. #1
    Junior Member
    Join Date
    Feb 2022
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question INT Operations Help Plz

    I have been trying to code this for days now even did research looked through the notes and everything I keep trying is not working and it's what is in the notes and readings, I done everything like it should me and keep getting errors. Here is the assignment:


    import java.util.Scanner;

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

    // Scanner is used for getting input.
    // Don't worry about this now.
    Scanner input = new Scanner(System.in);

    // These ints will be used for addition, subtraction and multiplication.
    System.out.println("What numbers would you like to do math with?");
    int x = input.nextInt();
    int y = input.nextInt();

    // Closing the scanner
    input.close();

    System.out.println(x + y);



    // 2. Print the difference of x and y.


    // 3. Print the product of x and y.


    // 4. Print the quotient of x and y.


    }
    }

    and these are the instructions:

    Int Operations
    Description:
    This activity will show you how to do simple math operations to int values. The values of int x and int y will be asked for in the console when you run the application yourself. You will have to put in two numbers you want to use. However for the test you just have to provide the code for printing out the sum, difference, product and quotient for x and y. Please follow the steps below:

    Steps:
    Print the sum of x and y. (line 18)
    Print the difference of x and y. (line 21)
    Print the product of x and y. (line 24)
    Print the quotient of x and y. (line 27)
    Test:
    Use the test provided. This test accounts for the print statements.

    Sample:
    Input:

    10
    2
    10
    2
    Output:

    What numbers would you like to do math with?
    12
    8
    20
    5


    Please can anyone help me.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: INT Operations Help Plz

    keep getting errors.
    Please copy the full text of the error message and paste it here. It has important info about the error.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    Note: The printed output would be easier to understand if there was some text with it.
    For example:
    System.out.println(x + y);   // prints a number but what does that number mean?
     
    System.out.println("sum="+ (x + y));   // prints "sum=" before the number making it more meaningful
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2022
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Re: INT Operations Help Plz

    It just keeps putting a ^ by the y or the x especially when I do the system.out.printin(x + y); for the sum of x and y also when I choose my numbers 20 and 10 its not letting I assumed I had to put them in these areas
    int x = input.nextInt(10);
    int y = input.nextInt(20);

    but that doesn't seem to be working the reading material and everything they gave us to study did not show an example of this and I can't move on until I figure this out. I am not necessary looking for the answer just an example I can look at to know where to start

    --- Update ---

    Also, the System.out.println(x + y); is what I wrote in there it was there it just said // 1. Print the sum of x and y but they had no numbers I have to choose two numbers. I don't know where to put the 10 and 20 for x and y because that is what I want my x and y to be and the System.out.println(x + y); is what I was trying to use to get the sum.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: INT Operations Help Plz

    Sorry, I am unsure what errors you are getting. Can you copy the full contents of the error messages and paste it here.
    How are you compiling the program? What program are you using?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Feb 2022
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Re: INT Operations Help Plz

    I am not getting an error no more I took everything out and left what they put in so this is the message I get when I run it:

    javac -classpath .:/run_dir/junit-4.12.jar:target/dependency/* -d . Main.java
     java -classpath .:/run_dir/junit-4.12.jar:target/dependency/* Main
    What numbers would you like to do math with?
    ^Cexit status 130

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: INT Operations Help Plz

    ^C
    Where does that come from? What numbers are you trying to enter as response to the question the program asks?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Feb 2022
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: INT Operations Help Plz

    I am trying to have x be 10 and y be 20 because I need lines 1-5 to come out like this:

    1. What numbers would you like to do math with?
    2. the sum needs to come out to 30 so I need x and y to add to that
    3. I need the difference to be 20
    4. I need the product of x and y to be 125
    5. and this line needs the quotient of x and y to be 5

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: INT Operations Help Plz

    Please post your current code wrapped in code tags so I can see what the code contains and what problems there are.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Feb 2022
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Re: INT Operations Help Plz

    Thats the problem I don't have anything posted what I posted this is what they gave me :

    import java.util.Scanner;

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

    // Scanner is used for getting input.
    // Don't worry about this now.
    Scanner input = new Scanner(System.in);

    // These ints will be used for addition, subtraction and multiplication.
    System.out.println("What numbers would you like to do math with?");
    int x = input.nextInt();
    int y = input.nextInt();

    // Closing the scanner
    input.close();


    // 1. Print the sum of x and y.



    // 2. Print the difference of x and y.


    // 3. Print the product of x and y.


    // 4. Print the quotient of x and y.


    }
    }



    THIS IS ALL THEY GAVE ME TO START WITH AND i HAVE TO PRINT A SUM THAT ADDS TO 30, THAT SUBTRACTS TO 20, MULTIPLIES TO 125 AND DIVIDES INTO 5.

    THIS MEANS THE SUMS OF X AND Y ARE:

    Y = 5 AND X =25
    I DON'T KNOW THE FORMULAE TO SHOW THE SUM X AND Y COMING OUT TO 30
    I DON'T KNOW THE FORMULAE NEEDED TO PRINT THEIR PRODUCT OF 125 AND THE SAME GOES FOR LINE 4 AND 5


    I JUST NEED SOME TO SHOW ME AN EXAMPLE OF A SUM FORMUALE, THE DIFFERENCE FORMULAE, PRODUCT FORMULAE, AND THE QUOTIENT FORMULAE IS ALL.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: INT Operations Help Plz

    EXAMPLE OF
    A SUM FORMUALE, 1 + 2
    THE DIFFERENCE FORMULAE, 2 - 1
    PRODUCT FORMULAE, AND 3 * 2
    THE QUOTIENT FORMULAE 3 / 2


    Again I ask this:
    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 1
    Last Post: August 15th, 2013, 04:39 PM
  2. Array Operations
    By knoxb in forum Collections and Generics
    Replies: 7
    Last Post: February 10th, 2012, 06:29 PM
  3. RPN Help Please! (Order of Operations)
    By yuvalb in forum What's Wrong With My Code?
    Replies: 6
    Last Post: September 30th, 2011, 10:53 AM
  4. Help with OS operations!
    By benglish in forum Java Theory & Questions
    Replies: 8
    Last Post: April 1st, 2011, 06:32 AM
  5. Operations with lists
    By datreta in forum Collections and Generics
    Replies: 8
    Last Post: October 29th, 2010, 08:54 AM

Tags for this Thread