AD

오늘 이력서 보낸 회사에서 보낸 문제와 답

Finjer22e63
2016-12-02 21:08:02 1320 1 12

----------문제---------

Instructions
1. You are required to demonstrate your problem solving skills using code. You may use your favourite IDE anddevelopment tool to test your code.
2. You may code in Java, Groovy, C#, JavaScript, C++ or C. Your code should only use the API from the standardlibrary and should not rely on third-party libraries to function.
3. Your code should be written inside the templates below. You should not write any code that prompts for userinput.
4. If you are submitting your answers online, please save them in a text file and name it submission.txt.

Programming Questions

1. Write a method to add up all even numbers in a range of numbers. The result should include the lower boundand upper bound numbers. 
Use the following template:
public int addEven(int lower, int upper) {
}

2. Write a method to return the average of an array of integers. 
Use the following template:
public double average(int[] numbers) {

}

3. Write a method to calculate the difference between 2 date values in month. E.g. the difference between28/02/2011 and 01/03/2011 is 1 month; the difference between 28/02/2011 and 01/03/2012 is 13 months; thedifference between 01/05/2011 and 31/05/2011 is 0 month. 
Use the following template:

public int differenceInMonth(Date fromDate, Date toDate) {

}



4. Write a method that generates a collection of random integers between 1 to 12 inclusive. The number of items toreturn is specified in the argument of the method. Use java.util.Randomto help you generate the randomnumbers. Use the following template:
public Collection<Integer> generateRandomNumbersBetween1And12(int count) {

}





------- 답 ---------


1. Write a method to add up all even numbers in a range of numbers. The result should include the lower boundand upper bound numbers. 
Use the following template:
public int addEven(int lower, int upper) {
int result = 0;
int counter;
for ( counter =  lower; counter <=upper; counter++){
if(counter %2 ==0)
result+=counter;
return result;

}

2. Write a method to return the average of an array of integers. 
Use the following template:
public double average(int[] numbers) {
int counter;
int sum = 0;
double result;
for(counter =0;counter< numbers.length; counter++){
sum+= numbers[counter];
}
result = (double) sum / 2;
return result;

}

3. Write a method to calculate the difference between 2 date values in month. E.g. the difference between28/02/2011 and 01/03/2011 is 1 month; the difference between 28/02/2011 and 01/03/2012 is 13 months; thedifference between 01/05/2011 and 31/05/2011 is 0 month. 
Use the following template:

public int differenceInMonth(Date fromDate, Date toDate) {

Calendar date1 = Calendar.getInstance();
date1.setTime(fromDate);

Calendar date2 = Calendar.getInstance();
date2.setTime(toDate);

int result =0;
//I have assumed that fromDate and toDate can be swapped. 
//If they are guaranteed to be correctly ordered, only the first if is necessary
//else is not needed due to no difference means 0 difference and its already set at top.
if(date1.compareTo(date2)<0){
result += ( date2.get(Calendar.YEAR) - date1.get(Calendar.YEAR) ) * 12;
result += ( date2.get(Calendar.MONTH) - date1.get(Calendar.MONTH) );
}
else if(date1.compareTo(date2)>0){
result += ( date1.get(Calendar.YEAR) - date2.get(Calendar.YEAR) ) * 12;
result += ( date1.get(Calendar.MONTH) - date2.get(Calendar.MONTH) );
}

return result;

}



4. Write a method that generates a collection of random integers between 1 to 12 inclusive. The number of items toreturn is specified in the argument of the method. Use java.util.Randomto help you generate the randomnumbers. Use the following template:
public Collection<Integer> generateRandomNumbersBetween1And12(int count) {

ArrayList<Integer> result = new ArrayList<Integer>();
Random random = new Random();

int counter;
for (counter=0; counter < count; counter++){
result.add(random.nextInt(12)+1);
}

return result;
}

---------------------

으앙 설마 이대로 진짜화 되가는건가 ... ㅠㅠ..

만약 첫월급 타면 후원좀 쏠게요...므엉
후원댓글 12
댓글 12개  
이전 댓글 더 보기
이 글에 댓글을 달 권한이 없습니다. 로그인해 보세요.
게임잡담질문/건의TIP클립게임추천도전나스닥
7
도전나스닥
도전나스닥 1년 정리
무적귀환쿨
03-28
19
게임
이제 이곳은 이주한다 [9]
Broadcaster 멀럭킹
03-25
14
잡담
오늘은 무슨날:? [5]
Broadcaster 멀럭킹
03-25
0
잡담
수건이 너무 낡아서 [5]
때껄룩
03-24
0
게임
아니 이게뭔데 십.. [1]
스페이스캣
03-23
0
게임
하스 투기장 조정됨 [1]
allfrom
03-22
0
03-21
0
03-21
0
게임
발라트로 신기록
산화이수소
03-20
13
03-19
0
게임
론울프 영상 다시보기 올려줘ㅠ [2]
그녀는멀럭을사랑한다
03-19
1
게임
론울프 영상 왜 안올라와!! [5]
그녀는멀럭을사랑한다
03-19
0
잡담
요즘 롯데리아 근황 [1]
때껄룩
03-18
1
03-18
2
03-18
2
03-18
2
게임
얼음 동굴 [1]
메디치
03-18
0
게임
배브 시야모드 멀씨 이거좀 깔고해 제발!!!
춘천성당수녀팬티도둑지우
03-18
1
질문/건의
오방없?? [2]
낭만땅콩군
03-18
5
게임
어디서 많이 본 비버마을
퍼스트에이드킷
03-18
인기글 글 쓰기