Answer to Question #16589 in Java | JSP | JSF for Sayed Abdullah Almousawi

Question #16589
Write a Java program that reads a sequence of 10 integers. The program should find the number of even integers, their sum, and the maximum even value.
1
Expert's answer
2012-10-17T09:41:40-0400
import java.io.*;

class AllEvenNum {

public static void main(String[] args) throws NumberFormatException,

IOException {




int evens[] = new int[10];

int sum = 0;

BufferedReader br1 = new BufferedReader(

new InputStreamReader(System.in));




for (int i = 0; i < 10; i++) {

System.out.println("Enter number : ");

int num = Integer.parseInt(br1.readLine());

evens[i] = num;

}




System.out.println("Evens: ");

int max = evens[0];

for (int i = 0; i < 10; i++) {

if (evens[i] % 2 == 0) {

System.out.print(evens[i] + " ");

if (evens[i] > max) {

max = evens[i];

}

sum += evens[i];

}

}

System.out.println("
Sum: " + sum);

System.out.println("Max: " + max);




}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS