Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / April 2005

Tip: Looking for answers? Try searching our database.

Question in arrays problem

Thread view: 
Kanaka Thamizhavel - 14 Apr 2005 16:14 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..
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.