BackJoon Algorithm 2576 홀수
BackJoon Algorithm - Java
문제
풀이
- 2로 나눴을때 나머지가 0이면 짝수 아니면 홀수
import java.util.Scanner;
public class Back_2576 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// given
int min=100;
int sum=0;
int count=0;
// when
for(int i=0;i<7;i++){
int number=sc.nextInt();
if(number%2!=0){
count++;
sum+=number;
if(number<min){
min=number;
}
}
}
sc.close();
// then
if(count==0){
System.out.println(-1);
}
else {
System.out.println(sum);
System.out.println(min);
}
}
}
댓글남기기