Homework 3 Solution 2

# Outprintln systemoutprintfproduct12fnproduct1

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 2: product2 += (quantity * prodprice2); break; case 3: product3 += (quantity * prodprice3); break; case 4: product4 += (quantity * prodprice4); break; case 5: product5 += (quantity * prodprice5); break; } }//end of else }//end of while loop //display results System.out.println(); System.out.printf( "Product 1: \$%.2f\n", product1 ); System.out.println(); System.out.printf( "Product 2: \$%.2f\n", product2 ); System.out.println(); System.out.printf( "Product 3: \$%.2f\n", product3 ); System.out.println(); System.out.printf( "Product 4: \$%.2f\n", product4 ); System.out.println(); System.out.printf( "Product 5: \$%.2f\n", product5 ); System.out.println("\n­­End­­"); } } 2. Triples.java The programs was succesfully compiled and run to produce the the triples up to 500. /**Program to calculate Pythagorean triples. */ public class Triples { public static void main(String args ){ // declare the three sides of a triangle int side1; int side2; int hypotenuse; for(side1 = 1; side1 <= 500­2; side1++) { for(side2 = side1 + 1; side2 <= 500­1; side2++) { for(hypotenuse =side2 + 1; hypotenuse <=500; hypotenuse++) { if( side1*side1 + side2*side2 == hypotenuse*hypotenuse){ System.out.println("Side1 = "+ side1); System.out.println("Side2 =...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online