Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class OddEvenPosition {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- double evenSum = 0.0;
- double oddSum = 0.0;
- double evenMaxNum = -1000000000.0;
- double evenMinNum = 1000000000.0;
- double oddMaxNum = -1000000000.0;
- double oddMinNum = 1000000000.0;
- for (int i = 0; i < n; i++) {
- double num = Double.parseDouble(scanner.nextLine());
- if (i % 2 == 1) {
- evenSum += num;
- if (num < evenMinNum) {
- evenMinNum = num;
- }
- if (num > evenMaxNum){
- evenMaxNum = num;
- }
- }
- else {
- oddSum += num;
- if (num < oddMinNum) {
- oddMinNum = num;
- }
- if (num > oddMaxNum){
- oddMaxNum = num;
- }
- }
- }
- DecimalFormat df = new DecimalFormat("#.##");
- System.out.println("OddSum="+ df.format(oddSum));
- if (oddMinNum == 1000000000) {
- System.out.println("OddMin=No");
- }
- else {
- System.out.println("OddMin=" + df.format(oddMinNum));
- }
- if (oddMaxNum == -1000000000) {
- System.out.println("OddMax=No");
- }
- else {
- System.out.println("OddMax=" + df.format(oddMaxNum));
- }
- System.out.println("EvenSum="+ df.format(evenSum));
- if (evenMinNum == 1000000000) {
- System.out.println("EvenMin=No");
- }
- else {
- System.out.println("EvenMin=" + df.format(evenMinNum));
- }
- if (evenMaxNum == -1000000000) {
- System.out.println("EvenMax=No");
- }
- else {
- System.out.println("EvenMax=" + df.format(evenMaxNum));
- }
- }
- }
Add Comment
Please, Sign In to add comment