关于JAVA的一道题
本帖最后由 liwenhao96 于 2018-4-9 05:45 编辑请删除此帖 import java.util.Scanner;
public class test {
publicstatic void main(String[] args) {
int b,n,s;
b=input("b");
n=input("n");
operation(b,n);
}
//input number
static int input(String msg){
int in;
while(true){
Scanner sc=new Scanner(System.in);
System.out.print("please input "+msg+": ");
in=sc.nextInt();
if ((in>=2) && (in<16)){
break;
}
System.out.println("please re-input, make sure it's a proper number 2-16");
}
return in;
}
//Get value M
static void operation(int b,int n){
int M=0;
for (int i=0;i<b;i++){
M=M+(int)Math.pow(n, i);
}
System.out.println("The M value is "+M);
prime(M);
}
//Check if it's a prime
static void prime(int m){
boolean flag=true;
for(int i=2;i<m;i++){
flag=false;
}
if(flag==true)
System.out.print("YES, CONGRATULATION");
else
System.out.print("SORRY, NO GIFT! ");
}
}
被英文吓尿了{:9_230:} wl872954075 发表于 2015-3-26 14:11
被英文吓尿了
哈哈
网上有用C++编的答案,只是我想用JAVA 先翻译成中文,OK? {:1_1:} {:1_1:} 求鱼币
页:
[1]