鱼C论坛

 找回密码
 立即注册
查看: 4414|回复: 7

关于JAVA的一道题

[复制链接]
发表于 2015-3-26 08:59:56 | 显示全部楼层 |阅读模式
50鱼币
本帖最后由 liwenhao96 于 2018-4-9 05:45 编辑

请删除此帖

最佳答案

查看完整内容

import java.util.Scanner; public class test { public static 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
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-3-26 08:59:57 | 显示全部楼层
import java.util.Scanner;
public class test {
        public  static 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! ");
        }

}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-3-26 14:11:48 | 显示全部楼层
被英文吓尿了
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2015-3-26 14:21:04 | 显示全部楼层

哈哈
网上有用C++编的答案,只是我想用JAVA
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-4-10 08:44:12 | 显示全部楼层
先翻译成中文,OK?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-4-12 21:31:24 | 显示全部楼层
{:1_1:}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-4-13 09:27:18 | 显示全部楼层
{:1_1:}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2015-4-13 10:08:35 | 显示全部楼层
求鱼币
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-24 03:59

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表