【发布时间】:2015-11-15 23:03:26
【问题描述】:
这个程序有效.. 我在没有使用 switch 的情况下对其进行了测试.. 我唯一的问题是不知道如何调用 whichtable(int number) 方法。
package switchmathtables;
import javax.swing.JOptionPane;
public class MathTables {
public static void printAddition(int x){
int i = 1;
while (x <= 12){
System.out.print (0 + x + " ");
x = x + 1;
}
System.out.println ("");
}
public static void printSinTable(){
double x, y, z;
System.out.print("Angle 30 degree ");
x = 30 * Math.PI/180;
System.out.println ("sin(" + x + ") is " + Math.asin(x));
System.out.print("Angle 60 degree ");
y = 30 * Math.PI/180;
}
public static void printCosTable(){
double x, y, z;
System.out.print("Angle 30 degree ");
x = 30 * Math.PI/180;
System.out.println ("cos(" + x + ") is " + Math.acos(x));
System.out.print("Angle 60 degree ");
y = 30 * Math.PI/180;
}
public static void printTanTable(){
double x, y, z;
System.out.print("Angle 30 degree ");
x = 30 * Math.PI/180;
System.out.println("tan(" + x + ") is " + Math.atan(x));
System.out.print("Angle 60 degree ");
y = 30 * Math.PI/180;
}
public static void printCommonLog(){
double x = 0.5;
while(x < 10) {
System.out.println( x + " " + Math.log(x) / Math.log(10));
x = x + 0.05;
}
}
这是我想从我的 main 调用的 void switch 方法。我也不知道是怎么回事
public static void printAddition(){
int x = 1;
while (x <= 12){
System.out.print (0 + x + " ");
x = x + 1;
}
System.out.println ("");
}
public static void whichtable(int number){
switch (number){
case 1:
printCommonLog();
break;
case 2:
printAddition();
break;
case 3:
printTanTable();
break;
case 4:
printCosTable();
break;
case 5:
printSinTable();
break;
}
这是我的主要内容,我想在其中调用 whichtable(int number) 方法..
}
public static void main(String[] args) {
int number;
String inputStr = JOptionPane.showInputDialog ("Type 1 for CommonLog table"
+ "Type 2 for Addition table"
+ "Type 3 for the tangent table"
+ "Type the 4 for the cosine table"
+ "Type the 5 for the sine");
}}
【问题讨论】:
标签: java methods parameters