Question
This program has an 'else without if' error. line 40 Your help is great. import javax.swing.JOptionPane; public class SortedNames { public void main(String[] args) {
This program has an 'else without if' error.
line 40
Your help is great.
import javax.swing.JOptionPane;
public class SortedNames
{
public void main(String[] args)
{
String name1;
String name2;
String name3;
name1 = JOptionPane.showInputDialog
("Enter first name ");
name2 = JOptionPane.showInputDialog
("Enter second name ");
name3 = JOptionPane.showInputDialog
("Enter third name ");
if(name1.compareTo(name2) < 0)
{
if(name2.compareTo(name3) < 0)
{
JOptionPane.showMessageDialog(null, name1 + ", "
+ name2 + " and" + name3);
}
else
{
if(name3.compareTo(name1) < 0)
{
JOptionPane.showMessageDialog(null, name3 + ", "
+ name1 + " and" + name2);
}
else
{
JOptionPane.showMessageDialog(null, name1 + ", "
+ name3 + " and" + name2);
}
}
else
{
if(name3.compareTo(name1) < 0)
{
JOptionPane.showMessageDialog(null, name2 + ", "
+ name3 + " and" + name1);
}
else
{
if(name3.compareTo(name2) < 0)
{
JOptionPane.showMessageDialog(null, name3 + ", "
+ name2 + " and" + name1);
}
else
{
JOptionPane.showMessageDialog(null, name2 + ", "
+ name1 + " and" + name3);
}
}
}
System.exit(0);
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started