Iterative Constructs in Java — Question 15
Back to all questionsQuestion 11
Write a program to input n number of integers and find out:
i. Number of positive integers
ii. Number of negative integers
iii. Sum of positive numbers
iv. Product of negative numbers
v. Average of positive numbers
import java.util.Scanner;
public class KboatIntegers
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int pSum = 0, pCount = 0, nPro = 1, nCount = 0;
System.out.println("Enter n:");
int n = in.nextInt();
System.out.println("Enter " + n + " integers:");
for (int i = 1; i <= n; i++) {
int num = in.nextInt();
if (num >= 0) {
pSum += num;
pCount++;
}
else {
nPro *= num;
nCount++;
}
}
double pAvg = pSum/(double)pCount;
System.out.println("Positive Integers = " + pCount);
System.out.println("Negative Integers = " + nCount);
System.out.println("Sum of Positive = " + pSum);
System.out.println("Product of Negative = " + nPro);
System.out.println("Average of Positive = " + pAvg);
}
}Output

Key Concepts Covered
This question tests your understanding of the following concepts from the chapter Iterative Constructs in Java: Question, Program, Input, Number, Integers, Out. These are fundamental topics in Computer Applications that students are expected to master as part of the ICSE Class 10 curriculum.
A thorough understanding of these concepts will help you answer similar questions confidently in your ICSE examinations. These topics are frequently tested in both objective and subjective sections of Computer Applications papers. We recommend revising the relevant section of your textbook alongside practising these solved examples to build a strong foundation.
How to Approach This Question
Read the question carefully and identify what is being asked. Break down complex questions into smaller parts. Use the terminology and concepts discussed in this chapter. Structure your answer logically — begin with a definition or key statement, then provide supporting details. Review your answer to ensure it addresses all parts of the question completely.
Key Points to Remember
- Write programs with proper indentation and comments.
- Trace through your code with sample inputs to verify correctness.
- Explain the logic behind each step of your solution.
- Familiarise yourself with common library functions and methods.
Practice more questions from Iterative Constructs in Java — Computer Applications, Class 10 ICSE