



“Complete Exercise 2.24 from the text. Provide your source code here in the body of the post with a screen shot” of everything.
Quoting Professor Brooke-Fishinghawk






More Options ...

Categories
Tag Cloud
Blog RSS
Comments RSS
Void (Default)
Life
Earth
Wind
Water
Fire
Lightweight
5:42 pm - April 5th, 2009
originally posted: 1 Mar 09 2:16 AM MST
Hello, surprisingly, the exercise was a small challenge; because the rules were to ONLY use the programming skills I learned within chapter 2! I found myself using more advanced methods. I flipped through that entire chapter about 10 times; just to make sure I could use a certain command! LOL… So solving the problem was not a challenge. But creating the program using only what we have learned from chapter 2 was a slight challenge. It’s easy to get carried away.
Here’s my source code:
/**
* @author RyanJB, Ryan Bridglal,
*
*University of Advancing Technology
*CSC203-D09FEB05
*Professor Estabrook-Fishinghawk
*02-28-09
*
*
* Instructions: Write an application that reads five integers,
* determines and prints the largest and smallest integers in
* the group. Use only the programming techniques learned within
* the chapter.
*/
import java.util.Scanner;
public class HighLowInteger {
public static void main(String[] args) {
//this allows the console to receive input
Scanner input = new Scanner(System.in);
//this identifies the variables
int Number1;
int Number2;
int Number3;
int Number4;
int Number5;
int LargeNumber;
int SmallNumber;
//introduction and begin program
System.out.print(”Welcome to the High-Low # program!\nEnter 5 numbers of your choice,\nand I will tell you what the highest\nand lowest numbers were.\n\nPlease enter your first number:”);
Number1 = input.nextInt();
System.out.print(”Enter your second number:”);
Number2 = input.nextInt();
System.out.print(”Enter your third number:”);
Number3 = input.nextInt();
System.out.print(”Enter your fourth number:”);
Number4 = input.nextInt();
System.out.print(”Enter your fifth number:”);
Number5 = input.nextInt();
//this calculates the largest number
LargeNumber = Number1;
if (Number1 > LargeNumber)
LargeNumber = Number1;
if (Number2 > LargeNumber)
LargeNumber = Number2;
if (Number3 > LargeNumber)
LargeNumber = Number3;
if (Number4 > LargeNumber)
LargeNumber = Number4;
if (Number5 > LargeNumber)
LargeNumber = Number5;
//this calculates the smallest number
SmallNumber = Number1;
if (Number2 < SmallNumber)
SmallNumber = Number2;
if (Number3 < SmallNumber)
SmallNumber = Number3;
if (Number4 < SmallNumber)
SmallNumber = Number4;
if (Number5 < SmallNumber)
SmallNumber = Number5;
//displays the numbers and goodbye!
System.out.println(”\nI’ve got your numbers and sorted\nthem based on the highest and lowest;\nhere’s the result:”);
System.out.printf(”\n The Highest number is:%d”, LargeNumber);
System.out.printf(”\n The Smallest number is:%d”, SmallNumber);
System.out.println(”\n\nGoodBye!”);
}
}
and here’s my screen shot:
5:45 pm - April 5th, 2009