?
Solved

java if staatement

Posted on 2008-11-12
3
Medium Priority
?
267 Views
Last Modified: 2012-05-05
I am determine which of the two randomly generated integers is the larger of the two and display it to the scree in the last JOption statement.  

JOptionPane.showMessageDialog(null, "The larger of the two numbers " + (value) + " and " + num + " is ");


any help would greatly be appreciated.
**************************************
package randomtester;
import java.util.Random;
import javax.swing.JOptionPane;
public class Main
{  
    public static void main(String[] args)
    {
        String input;
       
      Random generator = new Random();
     
 int num;
  num = generator.nextInt(100);
 
int value;
     input = JOptionPane.showInputDialog("Please enter a number of your choice");
  //  value = Double.parseDouble(input);
     value = Integer.parseInt(input);
     
     JOptionPane.showMessageDialog(null, "The First random number picked was " + (value));
     JOptionPane.showMessageDialog(null, "The second random number picked was " + (num));
     
     
         
     JOptionPane.showMessageDialog(null, "The larger of the two numbers " + (value) + " and " + num + " is ");
    }

}
0
Comment
Question by:ca1358
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 2000 total points
ID: 22946414
You can do an inline IF here:

JOptionPane.showMessageDialog(null, "The larger of the two numbers " + value + " and " + num + " is " + ((value > num)?value:num));

(condition)?true:false
0
 

Author Closing Comment

by:ca1358
ID: 31516244
Thank you!
0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 22946686
You are welcome!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question