Untitled
unknown
plain_text
2 months ago
892 B
5
Indexable
public class TwoFloats { public static void main(String[] args) { // Declare and initialize two floating-point variables float num1 = 5.5f; float num2 = 7.8f; // Calculate the sum, difference, and product float sum = num1 + num2; float difference = num1 - num2; float product = num1 * num2; // Cast the results to integers int intSum = (int) sum; int intDifference = (int) difference; int intProduct = (int) product; // Print the values of the two floats and the results of the operations System.out.println("two floats are: " + num1 + " " + num2); System.out.println("sum is: " + intSum); System.out.println("difference is: " + intDifference); System.out.println("product is: " + intProduct); } }
Editor is loading...
Leave a Comment