-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP1.java
34 lines (30 loc) · 1.04 KB
/
P1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package Programs;
import java.util.Scanner;
public class P1
{
//write a program to compute the sum of 5 positive number using continue;
public static void main(String[] args)
{
// created an variable of data type double
double number, sum = 0.0;
// creat an object of scanner
Scanner input = new Scanner(System.in);
for (int i = 1; i < 6; ++i)
{
System.out.print("Enter number " + i + " : ");
number = input.nextDouble();
//if number is negative
// continue statement is executed
if (number <= 0.0)
{
continue;
//Here, when the user enters a negative number, the continue statement is executed.
// This skips the current iteration of the loop and takes the program control to
// the update expression of the loop.
}
sum += number;
}
System.out.println("Total Sum of 5 positive no: " + sum);
input.close();
}
}