C++编程:从键盘输入10个国家名字,编程实现这10个国家的名字按字母升序输出。

如题所述

// Filename: country.java
// This program is used for outputing the countries according to the user input;
//
// Paper solution;
// 1. Catch the first letter from user input;
// 2. Transfer into switch statement;
// 3. Output all possible country names as string;
// 4. Display warning message to warn a wrong user input;
// 5. If wrong, continue the warning message until get a valid user input;

import java.io.*;
import java.io.IOException;
import java.util.*;
import javax.swing.JOptionPane;
import java.lang.*;
import java.lang.String;

public class country
{
public static void main (String[] args)
{

// 1. Catch the first letter from user input;

String topLetter = JOptionPane.showInputDialog(null, "Please input the first letter of the country", "TopLetter", JOptionPane.QUESTION_MESSAGE);

char a = topLetter.charAt(0);

// 2. Transfer into switch statement;

switch (a)

{

// 3. Output all possible country names as string;

case 'E': JOptionPane.showMessageDialog(null,"England","Country Name",JOptionPane.INFORMATION_MESSAGE);
break;

case 'F': JOptionPane.showMessageDialog(null,"France","Country Name",JOptionPane.INFORMATION_MESSAGE);
break;

case 'S': JOptionPane.showMessageDialog(null,"Switzerland, Slovakia, Slovenia, Spain, Serbia","Country Name",JOptionPane.INFORMATION_MESSAGE);
break;

case 'P': JOptionPane.showMessageDialog(null,"Portugal","Country Name",JOptionPane.INFORMATION_MESSAGE);
break;

case 'H': JOptionPane.showMessageDialog(null,"Holland","Country Name",JOptionPane.INFORMATION_MESSAGE);
break;

case 'I': JOptionPane.showMessageDialog(null,"Italy","Country Name",JOptionPane.INFORMATION_MESSAGE);
break;

case 'G': JOptionPane.showMessageDialog(null,"Germany","Country Name",JOptionPane.INFORMATION_MESSAGE);
break;

case 'D': JOptionPane.showMessageDialog(null,"Denmark","Country Name",JOptionPane.INFORMATION_MESSAGE);
break;

/*

case 'F': System.out.println("France"); break;

case 'S': System.out.println("Switzerland, Slovakia, Slovenia, Spain, Serbia"); break;

case 'P': System.out.println("Portugal"); break;

case 'H': System.out.println("Holland"); break;

case 'I': System.out.println("Italy"); break;

case 'G': System.out.println("Germany, Greece"); break;

case 'D': System.out.println("Denmark"); break;

*/

// 4. Display warning message to warn a wrong user input;

default: JOptionPane.showMessageDialog(null,"Incorrect input, please input the right country name","Warning Message",JOptionPane.INFORMATION_MESSAGE);

//default: System.out.println("Incorrect input, please input the right country name");

}
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-11-12
存入数组后,冒泡排序一下,输出即可,可能需要二维数组的知识
第2个回答  2013-11-12
跳水的 ?还是 羽毛球啊

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网