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

I have written the following code in java, but my professor has commented this \

ID: 3880280 • Letter: I

Question

I have written the following code in java, but my professor has commented this "You have integer division(the decimal part will be truncated) in avg = (test1+test2+test3)/3;, numerator and denominator are both integers" I just need help with the following code.

import java.util.Scanner;

public class Problem6 {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner kb = new Scanner (System.in);

System.out.println("Enter your first integer: ");

int test1 = kb.nextInt();

  

kb.nextLine();

  

  

System.out.println("Enter your 2nd integer: ");

int test2 = kb.nextInt();

  

kb.nextLine();

System.out.println("Enter your 3rd integer: ");

int test3 = kb.nextInt();

  

kb.nextLine();

  

int sum = test1+test2+test3;

  

System.out.println("The sum of your numbers are: "+sum);

  

double avg = (test1+test2+test3)/3;

  

  

System.out.println("The average of your numbers are: " +avg);

}

}

Explanation / Answer

Problem6.java

import java.util.Scanner;

public class Problem6 {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner kb = new Scanner(System.in);

System.out.println("Enter your first integer: ");

int test1 = kb.nextInt();

kb.nextLine();

System.out.println("Enter your 2nd integer: ");

int test2 = kb.nextInt();

kb.nextLine();

System.out.println("Enter your 3rd integer: ");

int test3 = kb.nextInt();

kb.nextLine();

int sum = test1 + test2 + test3;

System.out.println("The sum of your numbers are: " + sum);

double avg = (test1 + test2 + test3) / 3.0;

System.out.printf("The average of your numbers are: %.2f" , avg);

}

}

________________

Output:

Enter your first integer:
45
Enter your 2nd integer:
56
Enter your 3rd integer:
78
The sum of your numbers are: 179
The average of your numbers are: 59.67

_______________Could you plz rate me well.Thank You