Java对话框实现字符串反转,字符串大小写转换的程序实现

xiaoxiao2021-02-28  87

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; } } } }
转载请注明原文地址: https://www.6miu.com/read-37342.html

最新回复(0)