Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with Arrays Please  RSS feed

 
john leeman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int scores[] = {18, 19, 28, 13, 5, 25, 35};


I am trying to display the LOWEST SCORE ONLY in JOptionPane.showMessageDialog.

The lowest score which is 5.

How do I do it?
Please help.

Thanks in advance.
 
Andrew Nomos
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly is your difficulty: Getting the lowest score out of the array or displaying it in JOptionPane?
 
john leeman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Getting the lowest score out of the array

I don't know how to display only the lowest score "5".

All the examples I have are sorting from lowest to highest. But I want it to only get the lowest score, which is 5.

I know JOptionPane. Just the array I am having problems with.

[ June 02, 2005: Message edited by: john leeman ]
[ June 02, 2005: Message edited by: john leeman ]
 
ganesh pol
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i think this might Work

public class A1 {
static int a = 0;
public static void main(String args[]) {
int s[] = {
18, 19, 28, 13, 5, 25, 35};

System.out.println(s.length);

for (int i = 0; i < s.length; i++) {
for (int j = (i + 1); j < (s.length - 1); j++) {
a = Math.min(s[i], s[j]);

}
}
System.out.println(a);
}
}

 
john leeman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ganesh pol:
hi i think this might Work

public class A1 {
static int a = 0;
public static void main(String args[]) {
int s[] = {
18, 19, 28, 13, 5, 25, 35};

System.out.println(s.length);

for (int i = 0; i < s.length; i++) {
for (int j = (i + 1); j < (s.length - 1); j++) {
a = Math.min(s[i], s[j]);

}
}
System.out.println(a);
}
}





nope, i seem to be getting:

7 and 5 for my output.

i only want 5.
[ June 02, 2005: Message edited by: john leeman ]
 
ganesh pol
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u have got 7 bcoz System.out.println(s.length);
 
john leeman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
o stupid me. i didn't notice that part.

i just changed it to JOptionPane.

its works.

thanks alot!
 
John Dell'Oso
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An alternative:



Regards,
JD
 
Megs Maquito
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The alternative code rocks!!! Shows how powerful java is.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey folks,

it's all well and good to help people here when they have questions, but generally we focus on helping them figure it out, rather than handing them the completed code.

thanks!!!
 
john leeman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the help guys. greatly appreciate it.
 
john leeman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by fred rosenberger:
Hey folks,

it's all well and good to help people here when they have questions, but generally we focus on helping them figure it out, rather than handing them the completed code.

thanks!!!


true, but that wasn't the entire code I was looking for, it was more partial. There was more too it. I was just stuck in that weird position of confusion, and need some breaking ideas.

But I know what you mean, and very true. That is the best way to learn.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!