Java Question. Create an application named Numbers whose main() method holds two
ID: 645306 • Letter: J
Question
Java Question.
Create an application named Numbers whose main() method holds two integer variables. Assign values to the variables. Pass both values to methods named sum() and difference(). Create the methods sum() and difference(); then compute the sum and difference between the values of two arguments, respectively. Each method should perform the appropriate computation and display the results. Save the application as Numbers.java.
Please let me know what IDE was used and will run.
Explanation / Answer
public class Numbers { public static void main(String[] args) { int valOne = 20; int valTwo = 37; Numbers num = new Numbers(); num.sum(valOne, valTwo); num.difference(valOne, valTwo); } private void sum(int i, int j) { System.out.println("Sum of " + i + " and " + j + " = " + (i + j)); } private void difference(int i, int j) { int diff = 0; if(i >= j) { diff = i - j; } else { diff = j - i; } System.out.println("Difference of " + i + " and " + j + " = " + diff); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.