最后一道的编程题目输入一个数字K ,对应的输出这个数可以被3,5,7整除的数字
比如K=1,2,3对应3,5,7

题目不难
用面向对象方法可以解决

Java的代码是
import java.util.Scanner;

public class A6 {
public static void main(String[] args){
        //input
        Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();   
    int d = k;
    int s = 1;  
    while(d>=0){
            if(check(s)==1){
                    d--;
                    s++;
            }else{
                    s++;
            }
    }
    int p = s - 1;
    System.out.println("the Kth number is: " + p);
}
static int check(int a){
        if((a%3)==0){
                return check(a/3);
        }else if((a%5)==0){
                return check(a/5);
        }else if((a%7)==0){
                return check(a/7);
        }else if(a == 1){
                return 1;
        }

        return 0;
}
}

经过调试无误

评分

参与人数 1学分 +6 收起 理由
admin + 6 感谢您为软院筒子们提供有用信息!

查看全部评分

共收到 4 条回复
xywhere · #2 · 2013-9-23 17:38:44  回复
这。。。。
antty · #3 · 2013-9-23 18:31:53  回复 支持 反对
谢谢分享,顶一个
antty · #4 · 2013-9-23 18:32:01  回复 支持 反对
谢谢分享,顶一个
terry · #5 · 2013-9-23 18:42:35  回复
看看吧
回帖
B Color Image Link Quote Code Smilies
Command + Enter
快速回复 返回顶部 返回列表