Hi,
My program has to calculate largest and smallest numbers from an input
array of 20 numbers within the range 0 to 100. No compilation error but no
output messages in the applet as well. Any help appreciated..
kanaka
import java.awt.*;
import java.applet.*;
public class Input extends Applet
{
private int [] n = {5, 7, 12, 19, 25, 30, 37, 41, 43, 50, 52, 55,
61, 63, 70, 76, 84, 88, 96, 99};
static void printLargestAndSmallestElements (int[] n, Graphics g)
{
int max = -1;
int min = 101;
for (int i = 0; i < n.length; i++)
{
if (max < n[i])
{
max = n[i];
}
if (min > n[i])
{
min = n[i];
}
}
g.drawString("The maximum element in the array is: " + max, 100, 100);
g.drawString("The minimum: " + min, 100, 130);
}
}
Arnaud Berger - 14 Apr 2005 16:19 GMT
Hi,
Is this method ever called ?
Is the provided code the whole code of your class ?
Regards,
Arnaud
> Hi,
> My program has to calculate largest and smallest numbers from an input
[quoted text clipped - 38 lines]
> --
> Message posted via http://www.javakb.com
Kanaka Thamizhavel - 14 Apr 2005 17:24 GMT
Thanx, Arnaud.
I guess i missed the whole point of invoking the method. I
got confused with arrays as it was newly introduced. Anyway i have fixed
the code with ur help.
import java.awt.*;
import java.applet.*;
public class Lab9 extends Applet
{
private int [] n = {5, 7, 12, 19, 25, 30, 37, 41, 43, 50, 52, 55,
61, 63, 70, 76, 84, 88, 96, 99};
private int max, min;
public void LargestAndSmallest()
{
max = -1;
min = 101;
for (int i = 0; i < n.length; i++)
{
if (max < n[i])
{
max = n[i];
}
if (min > n[i])
{
min = n[i];
}
}
}
public void paint (Graphics g)
{
LargestAndSmallest();
g.drawString("The largest number in this array is: " + max, 50, 50);
g.drawString("The smallest number in this array is: " + min, 50, 80);
}
}
Thomas Weidenfeller - 14 Apr 2005 16:25 GMT
> Hi,
> My program has to calculate largest and smallest numbers from an input
> array of 20 numbers within the range 0 to 100. No compilation error but no
> output messages in the applet as well. Any help appreciated..
You are missing almost all code that makes up an Applet. Have a look at
Sun's tutorial at http://java.sun.com/docs/books/tutorial/applet/index.html
In general, please consider posting beginner's questions to
comp.lang.java.help, and please keep in mind that we don't do homework here.
/Thomas

Signature
The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
Kanaka Thamizhavel - 14 Apr 2005 17:10 GMT
Hello thomas,
Thanx for replying. I really am a beginner in java
programming and i am striving to do better programming. I have no
intentions of asking anyone to do my home work. I don't think it's even
fair to ask someone to do and get credit for it. I just got a little
confused with arrays as it was newly introduced. Anyway i will try to
figure out what i am doing wrong and then ask for any help if i still can't
figure out.
k