Homework 2 Code

Homework 2 Code - file:/X|/cs101/Homework2_0.txt /* = Solve...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
file:///X|/cs101/Homework2_0.txt /* == Solve 3.5 from page 94 == Write a program that generates three single-digit integers and prompt the user to enter the addition of these three integers. */ import java.util.Scanner; public class Homework2_0 { public static void main(String[] args) { // generate the three integers. int num1 = (int) (Math.random() * 10); int num2 = (int) (Math.random() * 10); int num3 = (int) (Math.random() * 10); // prompt the user. System.out.print(num1 + " + " + num2 + " + " + num3 + " = "); Scanner input = new Scanner(System.in); if (input.nextInt() == num1 + num2 + num3) { System.out.print("Correct!"); } else { System.out.print("Incorrect! The answer was " + (num1 + num2 + num3) + "."); } // no errors. System.exit(0); } } file:///X|/cs101/Homework2_0.txt [4/29/2008 12:10:00 PM]
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
file:///X|/cs101/Homework2_1.txt /* == Solve 3.8 from page 94 == Write a program that sorts three integers. The integers are entered from the input dialogs and stored in variables num1, num2, and num3, respectively. The program sorts the numbers os that num1 <= num2 <= num3. */ import javax.swing.JOptionPane; public class Homework2_1 { public static void main(String[] args) { // prompt the user for the integers. int num1 = Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the first integer:",
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/29/2008 for the course CS 101L taught by Professor Vineyard during the Winter '07 term at Kettering.

Page1 / 5

Homework 2 Code - file:/X|/cs101/Homework2_0.txt /* = Solve...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online