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);
}
}
rezal
0
Newbie Poster
Recommended Answers
Jump to PostCan 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.
Jump to PostWhat 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 …
Jump to PostSorry, I have no idea how to make your IDE show all the warnings. It is important that you see them.
Jump to PostUse 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
Jump to PostWhat 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 …
All 18 Replies
rezal
0
Newbie Poster
NormR1
563
Posting Sage
Team Colleague
rezal
0
Newbie Poster
rezal
0
Newbie Poster
NormR1
563
Posting Sage
Team Colleague
rezal
0
Newbie Poster
NormR1
563
Posting Sage
Team Colleague
rezal
0
Newbie Poster
NormR1
563
Posting Sage
Team Colleague
rezal
0
Newbie Poster
NormR1
563
Posting Sage
Team Colleague
rezal
0
Newbie Poster
NormR1
563
Posting Sage
Team Colleague
scudzilla
32
Junior Poster
rezal
0
Newbie Poster
NormR1
563
Posting Sage
Team Colleague
rezal
0
Newbie Poster
NormR1
563
Posting Sage
Team Colleague
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.