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

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);

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!