Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions