Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
import java.util.Scanner; public class OddEvenCalculator { static Scanner sc = new Scanner(System.in); // method to getNum from console and return the number public static int getNum() { System.out.print("Enter integer: "); return sc.nextInt(); } // method to calculate total public static double calculateTotal(double total, int num) { return total + num; } // method to calculate average public static double calculateAverage(double total, int count) { if (count == 0) return 0; return total / count; } // main method public static void main(String[] args) { int num; int evenCount = 0, oddCount = 0; int count = 0; double total = 0; num = getNum(); while (num != 0) { total = calculateTotal(total, num); count++; if (num % 2 == 0) evenCount++; else oddCount++; num = sc.nextInt(); // read next number } double average = calculateAverage(total, count); System.out.println("Total:" + total); System.out.printf("Average:%.2f%n", average); System.out.println("Even: " + evenCount + " and Odd: " + oddCount); sc.close(); } }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)