Untitled
unknown
plain_text
4 months ago
825 B
4
Indexable
public class AveThreeInts { public static void main(String[] args) { // Declare and initialize three integer variables int num1 = 5; int num2 = 7; int num3 = 2; // Calculate the sum of the three integers int sum = num1 + num2 + num3; // Calculate the average by dividing the sum by 3 // Since we're working with integers, this division will result in an integer float average = (float) sum / 3; // Cast the sum to float to get a floating point result // Print the values of the three integers and the calculated average System.out.print("values of three integers are: " + num1 + " " + num2 + " " + num3); System.out.println(" and the average is: " + average); } }
Editor is loading...
Leave a Comment