# Thread: Finding largest and smallest integer

1. Member
Join Date
Jan 2008
Posts
2
Rep Power
0

## Finding largest and smallest integer

This code shows malicious behavior.Actually I dont know what is wrong.I can solve using max and min method but I have to do using if else so Pls help me.Here is my code:

import javax.swing.*;
public class Max_min {
public static void main(String[]args){
int a=0,b=0,c=0;
String numA,numB,numC;

numA=JOptionPane.showInputDialog( "Enter number A");
a=Integer.parseInt(numA);

numB=JOptionPane.showInputDialog( "Enter number B");
b=Integer.parseInt(numB);

numC=JOptionPane.showInputDialog( "Enter number C");
c=Integer.parseInt(numC);

if(a>b)
{
if(b>c){
JOptionPane.showMessageDialog(null," a is greatest and c is smallest");
}
else JOptionPane.showMessageDialog(null," a is greatest and b is smallest");

}
else if(b>a)
{
if(a>c){
JOptionPane.showMessageDialog(null," b is greatest and c is smallest");
}
else JOptionPane.showMessageDialog(null," b is greatest and a is smallest");
}
else if(c>b)
{
if(b>a){
JOptionPane.showMessageDialog(null," c is greatest and a is smallest");
}
else JOptionPane.showMessageDialog(null," c is greatest and b is smallest");

}
}
}
Last edited by mlhazan; 01-09-2008 at 04:35 AM.

2. Java Code:
```import javax.swing.*;

public class MaxTest {
public static void main(String[] args) {
int[][] vals = {
{ 7, 9, 3 }, { 9, 6, 3 }, { 6, 2, 9 },
{ 2, 3, 8 }, { 1, 3, 2 }, { 6, 1, 4 }
};
System.out.println(" a  b  c  greatest  smallest");
System.out.println("----------------------------");
for(int j = 0; j < vals.length; j++) {
int a = vals[j][0];
int b = vals[j][1];
int c = vals[j][2];
System.out.printf(" %d  %d  %d  ", a, b, c);

if(a>b) {
if(a > c) {
if(b > c) {
System.out.println("   a         c");
} else {
System.out.println("   a         b");
}
} else {  // (c > a)
System.out.println("   c         b");
}
} else {  // (b > a)
if(b > c) {
if(c > a) {
System.out.println("   b         a");
} else {
System.out.println("   b         c");
}
} else {  // (c > b)
System.out.println("   c         a");
}
}
}
}
}```

3. Member
Join Date
Jan 2008
Posts
2
Rep Power
0

## thank you

Originally Posted by hardwired
Java Code:
```import javax.swing.*;

public class MaxTest {
public static void main(String[] args) {
int[][] vals = {
{ 7, 9, 3 }, { 9, 6, 3 }, { 6, 2, 9 },
{ 2, 3, 8 }, { 1, 3, 2 }, { 6, 1, 4 }
};
System.out.println(" a  b  c  greatest  smallest");
System.out.println("----------------------------");
for(int j = 0; j < vals.length; j++) {
int a = vals[j][0];
int b = vals[j][1];
int c = vals[j][2];
System.out.printf(" %d  %d  %d  ", a, b, c);

if(a>b) {
if(a > c) {
if(b > c) {
System.out.println("   a         c");
} else {
System.out.println("   a         b");
}
} else {  // (c > a)
System.out.println("   c         b");
}
} else {  // (b > a)
if(b > c) {
if(c > a) {
System.out.println("   b         a");
} else {
System.out.println("   b         c");
}
} else {  // (c > b)
System.out.println("   c         a");
}
}
}
}
}```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•