Results 1 to 3 of 3
- 01-09-2008, 04:33 AM #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.
- 01-09-2008, 06:34 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"); } } } } }
- 01-12-2008, 10:30 PM #3
Member
- Join Date
- Jan 2008
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Finding Largest Prime Factor
By perito in forum New To JavaReplies: 7Last Post: 11-08-2010, 08:25 PM -
Largest string value (alphabetically)
By mew in forum New To JavaReplies: 3Last Post: 12-14-2007, 05:45 PM -
ArrayList problem (finding largest no)
By bugger in forum New To JavaReplies: 3Last Post: 12-12-2007, 12:47 PM -
Getting smallest possible Double value
By Java Tip in forum Java TipReplies: 0Last Post: 12-06-2007, 02:15 PM -
Finding largest no
By bugger in forum New To JavaReplies: 11Last Post: 11-29-2007, 12:49 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks