62,612
社区成员
发帖
与我相关
我的任务
分享
public class factorial {
public static void main(String[] args)
{
System.out.println("Please enter a int number:");
int b = 0;
try
{
b =System.in.read();
}
catch(Exception ex)
{
ex.printStackTrace();
}
System.out.println(mathod(b));
}
public static long mathod (int a)
{
if(a == 1)
return 1l;
else
{
return a*mathod(a-1);
}
}
}
public class fac {
public static void main(String[] args) {
System.out.println("Please enter a int number:");
int b = 0;
try {
b = System.in.read();
System.out.println(b);
b = b - '0';
System.out.println(b);
} catch (Exception ex) {
ex.printStackTrace();
}
System.out.println(mathod(b));
}
public static long mathod(int a) {
return a == 1 ? 1 : a * mathod(a - 1);
}
}
try
{
b =System.in.read()-'0'; // 换成数字0-9
}
catch(Exception ex)
{
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class factorial {
public static void main(String[] args)
{
System.out.println("Please enter a int number:");
int b = 0;
BufferedReader keyboard=new BufferedReader(new InputStreamReader(System.in));
try
{
b =Integer.parseInt(keyboard.readLine());
}
catch(Exception ex)
{
ex.printStackTrace();
}
System.out.println(b);
System.out.println(mathod(b));
}
public static long mathod (int a)
{
if(a == 1)
return 1l;
else
{
return a*mathod(a-1);
}
}
}