import java.util.*;
import java.io.*;
import javax.swing.*;
public class Question
{
public static void main(String args[])
{
System.out.println("There are have four questions,you can select 1 or 2
or 3,4,the program will tell you the answer!");
System.out.println("Now please input your select:");
Scanner in=new Scanner(System.in);
int n=in.nextInt();
switch(n)
{
case 1: test1(); break;
//case 2: test2(); break;
case 3: test3(); break;
case 4: test4(); break;
default : break;
}
}
public static void test1()
{
int number;
number=(int)(Math.random()*101);
if(number>60)
{
System.out.println("其值超过60!");
}
else
{
System.out.println("其值小于60!");
}
}
/*
pubilc static void test2()
{
int number;
number=(int)(Math.random()*101);
if(number>30&&number<59)
{
number+=5;
System.out.println("加5分");
}
else
{
System.out.println("不加5分");
}
}
*/
public static void test3()
{
int sum=0;
System.out.println("please input one number:");
Scanner in=new Scanner(System.in);
int n=in.nextInt();
for(int i=1;i<=n;i++)
{
sum+=i;
}
System.out.println("sum="+sum);
}
public static void test4()
{
int sum=0;
System.out.println("please input a number");
Scanner in=new Scanner(System.in);
int n=in.nextInt();
switch(n)
{
case 1: sum=1;break;
case 2: sum=n*n;break;
case 3: sum=n*n*n;break;
case 4: sum=n*n*n*n;break;
}
System.out.println("sum="+sum);
}
}
如果把方法test2注释掉,这个程序就没问题,可test2和test1 没有区别啊,为什么会这样?
[此贴子已经被作者于2007-3-30 8:12:51编辑过]