ITeye博客

判断能被几整除

hy2012_campus · 2014-12-12 09:34 · 编程语言 · Markdown

算法比较简单,只是为了循序渐进,几乎没有什么参考价值,非常基础,只是为了提醒自己每天要进步一点点,除了web上的大量的crud,也想做点别的事情慢慢的提高自己。

public static int quyu(long i){
		int x=0,y=0,z=0,he=0;
		if(i%3==0){
			x=1;
		}
		if(i%5==0){
			y=2;
		}
		if(i%7==0){
			z=4;
		}
		he = x + y + z;
		return he;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long inputInt = sc.nextLong();
		sc.close();
		switch(quyu(inputInt)){
			case 0:
				System.out.println("不能被任何数整除 ");
				break;
			case 1:
				System.out.println("能被3整除 ");
				break;
			case 2:
				System.out.println("能被5整除 ");
				break;
			case 3:
				System.out.println("能被3,5整除 ");
				break;
			case 4:
				System.out.println("能被7整除 ");
				break;
			case 5:
				System.out.println("能被3,7整除 ");
				break;
			case 6:
				System.out.println("能被5,7整除 ");
				break;
			case 7:
				System.out.println("能被3,5,7整除 ");
				break;
			default:
				System.out.println("有些情况没有考虑到!");
				break;
		}
	}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。