京东2019实习笔试部分编程题

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
 * 输入t组数,每一组数为N;
 * 找到N=x*y,其中x为偶数,y为奇数,找到了打印出来,否则输出"No"
 * @author lily
 * 
 */
public class Main {
	public static void main(String[] args) {
		System.out.println("222222");
		Scanner sc = new Scanner(System.in);
		// 接收测试样例数
		int nNum =0;
		int input=0;
		do{
			input=sc.nextInt();
		}while(!(input >=1 && input <= 1000));
		nNum=input;
		
		List<Integer> nList = new ArrayList<Integer>(nNum);
		// 接收测试样例
		try{
			for (int i = 0; i < nNum; ) {
				int inputN=0;
				do{
					inputN=sc.nextInt();
				}while(!(inputN >=2 && inputN < Math.pow(2,63)));
					nList.add(inputN);
					i++;
			  }
			}catch(ArrayIndexOutOfBoundsException e){
							System.out.println("数组越界!");
							e.printStackTrace();
		    }


		for (int i = 0; i < nList.size(); i++) {
			int N = nList.get(i);
			if (N % 2 != 0) {
				System.out.println("No");
			} else {
				int y = 0;
				y = findY(N);
				if (y != -1) {
					System.out.println(y + " " + (N / y));
				}
			}
		}
		sc.close();
	}


	
	public static int findY(int n) {
		int temp = 0;
		temp = n / 2;
		if (temp % 2 == 0) {
			findY(temp);
			return -1;
		} else {
			return temp;
		}
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值