伙计我一直在做我的任务,我只有1个错误。我没有任何想法来解决这个问题,所以你可以帮助我,或者如果你有建议只是编辑我的代码。错误是" JOptionPane类型中的方法showOptionDialog(Component,Object,String,int,int,Icon,Object [],Object)不适用于参数(null,String,int,int,null,对象[],对象)"
这是我的代码
import javax.swing.JOptionPane;
import java.util.Scanner;
public class FLABWORK3_ABUEL
{
static Scanner Scan = new Scanner (System.in);
public static void main(String[] args)
{
String choice;
String num1;
String string;
String Inverse;
int choicee, num2, response, length;
double squareroot;
Object[] options = {"Yes", "No"};
do {
choice = JOptionPane.showInputDialog("Main Menu" +
"\n 1. Square of a number" +
"\n 2. Square root a number" +
"\n 3. Cube of a number" +
"\n 4. Length of number" +
"\n 5. Inverse of a String");
choicee = Integer.parseInt(choice);
while (choicee > 5)
{
choice = JOptionPane.showInputDialog("Enter only 1-5!");
}
if (choicee == 1)
{
num1 = JOptionPane.showInputDialog("Enter an number.");
num2 = Integer.parseInt(num1);
num2 = num2*num2 ;
JOptionPane.showMessageDialog(null, "The square of the number: " + num2);
} else if (choicee == 2)
{
num1 = JOptionPane.showInputDialog("Enter a number.");
squareroot = Integer.parseInt(num1);
squareroot = Math.sqrt(squareroot);
JOptionPane.showMessageDialog(null, "Square root is: " + squareroot);
} else if (choicee == 3)
{
num1 = JOptionPane.showInputDialog("Enter a number.");
num2 = Integer.parseInt(num1);
num2 = num2*(num2*num2);
JOptionPane.showMessageDialog(null, "The cube is: " + num2);
} else if (choicee == 4)
{
string = JOptionPane.showInputDialog("Enter a sentence or a word.");
length = string.length();
JOptionPane.showMessageDialog(null, "The length : " + "\n" + length + "\n\n" +
"is:" + string);
}
else if (choicee == 5)
{
string = JOptionPane.showInputDialog("Enter a word.");
length = string.length();
for (int i = length - 1; i >= 0; i--)
Inverse = Inverse + string.charAt(i);
}
response = JOptionPane.showOptionDialog(null,
"Would you like to try again?",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,null, options, options[0]);
}
while (response == JOptionPane.YES_OPTION);
} }
答案 0 :(得分:0)
您没有正确数量的参数。这是showOptionDialog的结构:
showOptionDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue)
来自https://docs.oracle.com/javase/7/docs/api/javax/swing/JOptionPane.html