📄 exercise3_7.java
字号:
// Exercise3_5.java: Find total and average of input values
import javax.swing.JOptionPane;
public class Exercise3_7 {
public static void main(String[] args) {
int countPositive=0, countNegative = 0;
int count = 0, total = 0, num;
do {
// Read the next data
String dataString = JOptionPane.showInputDialog(null,
"Enter an int value, \nthe program exits if the input is 0",
"Exercise3_5 Input", JOptionPane.QUESTION_MESSAGE);
num = Integer.parseInt(dataString);
if (num > 0)
countPositive++;
else if (num < 0)
countNegative++;
total += num;
count++;
}
while (num != 0);
// Adjust count
count--;
if (count == 0)
System.out.println("You didn't enter any number");
else {
System.out.println("the number of postives is " + countPositive);
System.out.println("the number of negatives is " + countNegative);
System.out.println("the total is " + total);
System.out.println("the average is " + total * 1.0 / count);
}
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -