Java對話框實現字符串反轉,字符串大小寫轉換的程序實現

import javax.swing.JOptionPane;


public class InputDialogTest{
public static void main(String[] args){
String inputString=JOptionPane.showInputDialog(null,"請輸入一個英文單詞","輸入",JOptionPane.QUESTION_MESSAGE);

while(true){
Object[] option={"轉換爲大寫","轉換成小寫","反轉顯示"};
Object item=JOptionPane.showInputDialog(null,"請選擇","輸入",JOptionPane.INFORMATION_MESSAGE,null,option,option[0]);

String itemString=(String)item;
if(itemString.equals("轉換爲大寫")){
String str=inputString.toUpperCase();
JOptionPane.showMessageDialog(null,str,"操作結果",JOptionPane.INFORMATION_MESSAGE);
}else if(itemString.equals("轉換成小寫")){
String str=inputString.toLowerCase();
JOptionPane.showMessageDialog(null,str,"操作結果",JOptionPane.INFORMATION_MESSAGE);
}else{
String str=new StringBuffer(inputString).reverse().toString();
JOptionPane.showMessageDialog(null,str,"操作結果",JOptionPane.INFORMATION_MESSAGE);
}
int reponse=JOptionPane.showConfirmDialog(null,"是否繼續呢","菜單",JOptionPane.YES_NO_OPTION);
if(reponse==JOptionPane.NO_OPTION){
break;
}
}
}
}
發佈了34 篇原創文章 · 獲贊 21 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章