Answer to Question #259147 in Java | JSP | JSF for joy

Question #259147

3. 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

1
Expert's answer
2021-11-01T18:57:35-0400

Source code

import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
		double [] nums=new double[4];
		System.out.println("\nEnter four numbers separated by space: ");
		Scanner in =new Scanner(System.in);
		for (int i=0;i<4;i++){
		    nums[i]=in.nextDouble();
		}
		System.out.println();
		int count=0;
		for (int i=0;i<4;i++){
		    if (nums[i]>0)
		        count++;
		}
		System.out.println(count);
		
	}
}

Output





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS