码迷,mamicode.com
首页 > 其他好文 > 详细

HW4.1

时间:2016-08-13 21:10:44      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 1 import java.util.Scanner;
 2 
 3 public class Solution
 4 {
 5     public static void main(String[] args)
 6     {
 7         Scanner input = new Scanner(System.in);
 8 
 9         System.out.print("Enter an int value, the program exits if the input is 0: ");
10         int inputValue = input.nextInt();
11         int count = 1;
12 
13         int positive = 0;
14         int negative = 0;
15         if(inputValue > 0)
16             positive = 1;
17         else if(inputValue < 0)
18             negative = 1;
19 
20         int sum = inputValue;
21 
22         while(inputValue != 0)
23         {
24             System.out.print("Enter an int value, the program exits if the input is 0: ");
25             inputValue = input.nextInt();
26             count++;
27             sum += inputValue;
28             if(inputValue > 0)
29                 positive++;
30             else if(inputValue < 0)
31                 negative++;
32         }
33 
34         float average = (float)(sum * 1.0) / count;
35 
36         System.out.println("The number of positives is " + positive);
37         System.out.println("The number of negatives is " + negative);
38         System.out.println("The total is " + count);
39         System.out.println("The average is " + average);
40     }
41 }

 

HW4.1

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5768759.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!