The Positive Ones
by CodeChum Admin
There are different kinds of numbers, but among them all, the most commonly used numbers in our daily lives are those positive ones. So, I only want you to count all the positive numbers from the 4 outputted values and print out the result.
Go and search for the positive ones among these four!
Input
A line containing four numbers (may contain decimal places) separated by a space.
2·-4·3.6·1
Output
A line containing an integer.
3
import java.util.Scanner;
public class App {
/**
* The start point of the program
*
* @param args
*/
public static void main(String[] args) {
Scanner keyBoard = new Scanner(System.in);
String numbers[]=keyBoard.nextLine().split(" ");
int counter=0;
for(int i=0;i<4;i++) {
if(Integer.parseInt(numbers[i])>0) {
counter++;
}
}
System.out.println(counter);
keyBoard.close();
}
}
Comments
Leave a comment