URI Online Judge | 1060
Positive Numbers
Adapted by Neilor Tonin, URI Brazil
Timelimit: 1
Write a program that reads 6 numbers. These numbers will only be positive or negative (disregard null values). Print the total number of positive numbers.
Input
Six numbers, positive and/or negative.
Output
Print a message with the total number of positive numbers.
Input Sample | Output Sample |
7 -5 6 -3.4 4.6 12 | 4 valores positivos |
URI Online Judge Solution 1060 || Positive Numbers
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
double X;
int totalPositive = 0;
Scanner input =new Scanner(System.in);
for (int i = 0; i < 6; i++) {
X = input.nextDouble();
if (X > 0) {
totalPositive += 1;
}
}
System.out.print(totalPositive+" valores positivos\n");
}
}