• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with Arrays Please

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
o stupid me. i didn't notice that part.

i just changed it to JOptionPane.

its works.

thanks alot!
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An alternative:



Regards,
JD
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The alternative code rocks!!! Shows how powerful java is.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the help guys. greatly appreciate it.
 
john leeman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic