Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

**PROGRAMS MUST BE WRITTEN IN JAVA **MUST BE 2 SEPARATE PROGRAMS **Complete the

ID: 3873649 • Letter: #

Question

**PROGRAMS MUST BE WRITTEN IN JAVA

**MUST BE 2 SEPARATE PROGRAMS

**Complete the following code assignment in Eclipse.

A)

Write a Java class with a main method, that takes two integer values from the command line and i) displays the sum of the two values and ii) the product of the two values.  

B)

Write a Java class, with a main method, that takes two integers from the command line and displays on screen the non-zero multiples of the first integer, up to the number of the second integer.

For example if the two inputs are 4 and 6, then the output should be:

4
8
12
16
20
24

Explanation / Answer

A) Program 1

import java.util.Scanner;
public class AddMul { //Class name is AddMul
public static void main(String[] args) {
Scanner s = new Scanner(System.in);   
System.out.print("Enter first integer: "); //First user input
int Integer1 = s.nextInt(); // Reads the value and stores in Integer1
System.out.print("Enter second integer: "); //Second input
int Integer2 = s.nextInt(); //Reads the value and stores in Integer2
int sum = Integer1 + Integer2; //Condition for adding two integers
System.out.println("Sum of two values " + sum); //Prints the result of addition
int mul = Integer1 * Integer2; //Condition for multiplying two integers
System.out.println("Product of two values " + mul); //Prints the result of multiplication
}
}

B) Program 2

import java.util.Scanner;
public class MulOfInt { //Class name is MulOfInt(multiples of integer)
public static void main(String[] args) {   
Scanner s = new Scanner(System.in);   
System.out.print("Enter first integer: "); //First user input
int Integer1 = s.nextInt(); // Reads the value and stores in Integer1
System.out.print("Enter second integer: "); //Second input
int Integer2 = s.nextInt(); //Reads the value and stores in Integer2
for(int i=1;i<=Integer2;i++) //loop goes on until i<= second integer
{
int x = Integer1*i; // x is a temporary variable stores the output of first integer multiple
System.out.print(x+" "); // Prints the output to screen
}
}
}