Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-11-2011, 07:32 AM   PM User | #1
sabi
New Coder

 
Join Date: Oct 2011
Posts: 27
Thanks: 2
Thanked 0 Times in 0 Posts
sabi is an unknown quantity at this point
java inputDialog

How would you read single character from JOptionPane class:

import javax.swing.JOptionPane;


for example:

response = JOptionPane.showInputDialog("are you having fun? (Y=yes, N=no)");


So how would you read if the user entered Y or N
sabi is offline   Reply With Quote
Old 10-11-2011, 01:55 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,450 Times in 2,419 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
showInputDialog returns a string, so you'd use response.equals() in order to determine what was entered.
Fou-Lu is offline   Reply With Quote
Old 02-19-2012, 05:44 AM   PM User | #3
sabi
New Coder

 
Join Date: Oct 2011
Posts: 27
Thanks: 2
Thanked 0 Times in 0 Posts
sabi is an unknown quantity at this point
How to put names in alphabetical order

This is what I got but im getting an error in the if statements, so can someone help me fix this?


import java.util.Scanner;

public class Alpha
{
public static void main(String[] args)
{
String = name1;
String = name2;
String = name3;
Scanner keyboard = new Scanner(System.in);

System.out.println("Enter name one");
name1 = keyboard.nextLine();
System.out.println("Enter name two");
name2 = keyboard.nextLine();
System.out.println("Enter name three");
name3 = keyboard.nextLine();

if(name1.compareTo(name2) < 0) && (name1.compareTo(name3) < 0) && (name2.compareTo(name3) < 0)
{
System.out.println(name1 + name2 + name3);
}
else if(name2.compareTo(name1) < 0) && (name2.compareTo(name3) < 0) && (name1.compareTo(name3) < 0)
{
System.out.println(name2 + name1 + name3);
}
else if(name3.compareTo(name1) < 0) && (name3.compareTo(name2) < 0) && (name1.compareTo(name2) < 0)
{
system.out.println(name3 + name1 + name2);
}

}
}
sabi is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:38 PM.


Advertisement
Log in to turn off these ads.