Sunday, April 27, 2014

Program to display both the largest and smallest of a series of 5 integers
































































































































































































































































































































































































































































































































Hi dear programmers































































































































































































































































































































































































































































































































here is a simple program on applets that is giving me a bit of headache since it cannot always display the two numbers that it is supposed to: the largest and smallest of the five input integers.....I cannot see where i went wrong, can somebody help me see? you can always create separately the HTML file to load the applet in an appletviewer of your won size. kind regards.
































































































































































































































































































































































































































































































































*































































































































































































































































































































































































































































































































23.6 (Largest and Smallest) Write an applet that reads five integers, determines which are the































































































































































































































































































































































































































































































































largest and smallest integers in the group and prints them. Draw the results on the applet.































































































































































































































































































































































































































































































































*/































































































































































































































































































































































































































































































































import java.awt.Graphics;































































































































































































































































































































































































































































































































import javax.swing.JApplet;































































































































































































































































































































































































































































































































import javax.swing.JOptionPane;
































































































































































































































































































































































































































































































































public class Exercise23_6 extends JApplet































































































































































































































































































































































































































































































































{
































































































































































































































































































































































































































































































































// class attributes































































































































































































































































































































































































































































































































private int number1 ;































































































































































































































































































































































































































































































































private int number2 ;































































































































































































































































































































































































































































































































private int number3 ;































































































































































































































































































































































































































































































































private int number4 ;































































































































































































































































































































































































































































































































private int number5 ;































































































































































































































































































































































































































































































































// initialise applets elements































































































































































































































































































































































































































































































































public void init()































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































String firstN = JOptionPane.showInputDialog( "Enter first integer : " );































































































































































































































































































































































































































































































































String secondN = JOptionPane.showInputDialog( "Enter second integer : " );































































































































































































































































































































































































































































































































String thirdN = JOptionPane.showInputDialog( "Enter third integer : " );































































































































































































































































































































































































































































































































String fourthN = JOptionPane.showInputDialog( "Enter fourth integer : " );































































































































































































































































































































































































































































































































String fifthN = JOptionPane.showInputDialog( "Enter fifth integer : " );
































































































































































































































































































































































































































































































































// conversion of the String elements to integer































































































































































































































































































































































































































































































































number1 = Integer.parseInt( firstN );































































































































































































































































































































































































































































































































number2 = Integer.parseInt( secondN);































































































































































































































































































































































































































































































































number3 = Integer.parseInt( thirdN );































































































































































































































































































































































































































































































































number4 = Integer.parseInt( fourthN );































































































































































































































































































































































































































































































































number5 = Integer.parseInt( fifthN );































































































































































































































































































































































































































































































































} // end method init
































































































































































































































































































































































































































































































































// method paint































































































































































































































































































































































































































































































































public void paint( Graphics g )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































// calling superclass version of method paint































































































































































































































































































































































































































































































































super.paint( g );
































































































































































































































































































































































































































































































































// draw a rectangle































































































































































































































































































































































































































































































































g.drawRect( 10, 15, 500, 450 );
































































































































































































































































































































































































































































































































// displaying the input numbers































































































































































































































































































































































































































































































































g.drawString( "The input numbers are : ",50, 50 );































































































































































































































































































































































































































































































































g.drawString(" "+ number1, 50, 70);































































































































































































































































































































































































































































































































g.drawString( " "+ number2,60, 70 );































































































































































































































































































































































































































































































































g.drawString( " "+ number3, 70, 70 );































































































































































































































































































































































































































































































































g.drawString( " "+ number4, 80, 70 );































































































































































































































































































































































































































































































































g.drawString( " "+ number5, 90, 70 );































































































































































































































































































































































































































































































































// LARGEST































































































































































































































































































































































































































































































































if( number1 > number2 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number1 > number3 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number1 > number4 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number1 > number5 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































g.drawString( number1 +" is the greatest", 50,90 );































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































}// end if































































































































































































































































































































































































































































































































} // end if
































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































else if( number2 > number1 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number2 > number3)































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number2 > number4 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number2 > number5)































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































g.drawString( number2 +" is the greatest.", 50, 90 );































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end if
































































































































































































































































































































































































































































































































} // end else if































































































































































































































































































































































































































































































































else if( number3 > number1 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number3 > number2 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number3 > number4 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number3 > number5 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































g.drawString( number3 +" is the greatest.", 50, 90 );































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end if else































































































































































































































































































































































































































































































































else if( number4 > number1 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number4 > number2 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number4 > number3 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number4 > number5 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































g.drawString( number4 +" is the greatest.", 50, 90 );































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end if
































































































































































































































































































































































































































































































































} // end if else































































































































































































































































































































































































































































































































else if( number5 > number1 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number5 > number2 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number5 > number3 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number5 > number4 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































g.drawString( number5 +" is the greatest.", 50, 90 );































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end else if
































































































































































































































































































































































































































































































































// SMALLEST































































































































































































































































































































































































































































































































if( number1 < number2 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number1 < number3 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number1 < number4 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number1 < number5 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































g.drawString( number1 +" is the smallest", 50,100 );































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































}// end if































































































































































































































































































































































































































































































































} // end if
































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































else if( number2 < number1 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number2 < number3)































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number2 < number4 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number2 < number5)































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































g.drawString( number2 +" is the smallest.", 50, 100 );































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end if
































































































































































































































































































































































































































































































































} // end else if































































































































































































































































































































































































































































































































else if( number3 < number1 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number3 < number2 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number3 < number4 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number3 < number5 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































g.drawString( number3 +" is the smallest.", 50, 100 );































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end if else































































































































































































































































































































































































































































































































else if( number4 < number1 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number4 < number2 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number4 < number3 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number4 < number5 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































g.drawString( number4 +" is the smallest.", 50, 100 );































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end if
































































































































































































































































































































































































































































































































} // end if else































































































































































































































































































































































































































































































































else if( number5 < number1 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number5 < number2 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number5 < number3 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































if( number5 < number4 )































































































































































































































































































































































































































































































































{































































































































































































































































































































































































































































































































g.drawString( number5 +" is the smallest.", 50, 100 );































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end if































































































































































































































































































































































































































































































































} // end else if































































































































































































































































































































































































































































































































} // end method paint































































































































































































































































































































































































































































































































} // end class Exercise23_6































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































No comments:

Post a Comment