package maxmin;

import javax.swing.JOptionPane;

public class MaxMin 
{

    public static void main(String[] args) 
    {
        final int Tnum = 5;
        int num[] = new int[Tnum];


        for(int i=0; i<num.length; i++)
        {
           String numstring = JOptionPane.showInputDialog(null,"Please enter number: ","User Input",
           JOptionPane.QUESTION_MESSAGE);

           num[i] = Integer.parseInt(numstring);
        }

        int max = num[0];
        for(int i=0; i<num.length; i++)
        {
            if(max<num[i]);
            max = num[i];
        }    

        int min = num[0];
        for(int i=0; i<num.length; i++)
        {
            if (min>num[i]);
            min = num[i];
        }

        String MaxMin = "The array are : ";

        for(int i=0; i<num.length; i++)
        {
            MaxMin = MaxMin + num[i] + " ";    
        }    

        MaxMin = MaxMin + "\nThe largest number is "+max;
        MaxMin = MaxMin + "\nThe smallest number is "+min;

        JOptionPane.showMessageDialog(null,MaxMin,"Number",
        JOptionPane.INFORMATION_MESSAGE);

    }
}

Recommended Answers

All 18 Replies

cant seems to find the solution to separate the output for max and min

Can you explain what the problem is? What happens when you execute thte code.
Please add printlns to the code to show what the code does when it is executed and post the output here.

the max and min value in dialog box come out with the same integer..
when i make a few change to this program the dialog box do not even come out

by thw way it is the message dialog box do not appear..

What was printed out when you added the printlns I asked you to add to the program to show what it is doing?

You need to add the -Xlint option to the javac compiler command so it prints out warning statements for problems in your code.
You have a coding problem that the compiler will warn you about if you use that option.

-Xlint option to

i used netbean... is it the same on how to use it?

Sorry, I have no idea how to make your IDE show all the warnings. It is important that you see them.

Use the javac compiler with the -Xlint option. It will show you where the problems are. Here is the commandline I use to compile programs:
D:\Java\jdk1.7.0\bin\javac.exe -Xlint TestCode7.java

-Xlint TestCode7.java

like this?? btw i m a beginner

What version of the JDK are you using? javac -version

Copy and paste here the console's contents for when you tried to compile the program:
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.

    sdk 1.4


    C:\Users\user>\\cd
    The filename, directory name, or volume label syntax is incorrect.


    C:\Users\user>cd\

    C:\>cd\

    C:\>j2sdk\bincd\
    'j2sdk\bincd\' is not recognized as an internal or external command,
    operable program or batch file.

    C:\>j2sdk\bin\cd\
    'j2sdk\bin\cd\' is not recognized as an internal or external command,
    operable program or batch file.

    C:\>j2sdk\bin\javac.exe -Xlint MaxMin.java
    javac: invalid flag: -Xlint
    Usage: javac <options> <source files>
    where possible options include:
      -g                        Generate all debugging info
      -g:none                   Generate no debugging info
      -g:{lines,vars,source}    Generate only some debugging info
      -nowarn                   Generate no warnings
      -verbose                  Output messages about what the compiler is doing
      -deprecation              Output source locations where deprecated APIs are us
    ed
      -classpath <path>         Specify where to find user class files
      -sourcepath <path>        Specify where to find input source files
      -bootclasspath <path>     Override location of bootstrap class files
      -extdirs <dirs>           Override location of installed extensions
      -d <directory>            Specify where to place generated class files
      -encoding <encoding>      Specify character encoding used by source files
      -source <release>         Provide source compatibility with specified release
      -target <release>         Generate class files for specific VM version
      -help                     Print a synopsis of standard options


    C:\>j2sdk\bin\-Xlint MaxMin.java
    'j2sdk\bin\-Xlint' is not recognized as an internal or external command,
    operable program or batch file.

    C:\>

1.4 is a very old version of java. The current version is 1.7
Can you update to a more current version?

At lines 25 and 32, remove the semicolon. Because of those semicolons, max and min are both assigned to the final number in the array.

i think i have installed thats why i can use netbean..

What version of java does your IDE use?

netbean need sdk 7 in order to use it.. but i do not know how to run console by using 7, only netbean... cn u give tell me how to use 7? i m a student anyway.. lot of thing need to learn..
btw the code sollved i done it..

To use a command in the command prompt, the OS must know how to find the command. On Windows, you tell the OS where a command is located is by adding an entry to the PATH environment variable. The PATH variable contains paths to folders where .exe files are located.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.