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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started