Page 217 - CA_Blue( J )_Class9
P. 217
4 public static void main(String[] args)
5 {
6 Scanner sc = new Scanner(System.in);
7 int num;
8 double sum = 0;
9 System.out.print ("Enter number of terms of series : ");
10 num = sc.nextInt();
11 for(int i = 1; i <= num; i++)
12 {
14 sum += 1.0/i;
15 }
16 System.out.print1n ("sum: " + sum);
17 }
18 }
You will get the following output:
Write a program to enter the numbers till the user wants and at the end it should display the
Program 7
count of positive, negative and zeros entered.
1 import java.util.*;
2 public class num_count
3 {
4 public static void main(String[] args)
5 {
6 Scanner sc = new Scanner(System.in);
7 int num,p=0,n=0,z=0;
8 char choice;
9 do
Iterative Constructs in Java 215

