`
hy2012_campus
  • 浏览: 30975 次
  • 性别: Icon_minigender_1
  • 来自: 河南
社区版块
存档分类
最新评论

判断能被几整除

 
阅读更多

算法比较简单,只是为了循序渐进,几乎没有什么参考价值,非常基础,只是为了提醒自己每天要进步一点点,除了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;
		}
	}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics