我做了一个程序来识别正方形,平方根,数字立方体和字符串的反转我有一些错误我没有一个想法来解决这个问题。rroReturn类型方法丢失,YES_NO_OPTION无法解决一些错误
这里是我的下面
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;
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!");
}
switch (choicee)
{
case 1:
num1 = JOptionPane.showInputDialog("Enter an number.");
num2 = Integer.parseInt(num1);
num2 = num2*num2 ;
JOptionPane.showMessageDialog(null, "The square of the number: " + num2);
break;
case 2:
num1 = JOptionPane.showInputDialog("Enter a number.");
squareroot = Integer.parseInt(num1);
squareroot = Math.sqrt(squareroot);
JOptionPane.showMessageDialog(null, "Square root is: " + squareroot);
break;
case 3:
num1 = JOptionPane.showInputDialog("Enter a number.");
num2 = Integer.parseInt(num1);
num2 = num2*(num2*num2);
JOptionPane.showMessageDialog(null, "The cube is: " + num2);
break;
case 4:
string = JOptionPane.showInputDialog("Enter a sentence or a word.");
length = string.length();
JOptionPane.showMessageDialog(null, "The length : " + "\n" + length + "\n\n" +
"is:" + string);
break;
case 5:
string = JOptionPane.showInputDialog("Enter a word.");
length = string.length();
for (int i = length - 1; i >= 0; i--)
Inverse = Inverse + string.charAt(i);
JOptionPane.showInputDialog(null, "Would you like to ry again?"
JOptionPane.YES_NO_OPTION,
JOptionPane.Question_Message, null, options, options [0]);
}
}
while (response == JOptionPane.YES_OPTION);
}
}
代码是更好地做切换的情况下,或者如果else语句? 错误是返回类型方法是缺少静态扫描仪和YES_NO_OPTION不能解决
确切的错误是什么? – Raptor 2014-12-03 08:59:08
这与您的问题完全无关,但您应该习惯[Java命名约定](http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-135099.html#367):class名字应该是LikeThis,像this这样的变量等等。例如,如果我看到名为'Inverse'或'Scan'的东西,我希望它们是类,而不是变量。 – AJPerez 2014-12-03 09:15:17