-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNegPosZero.java
110 lines (79 loc) · 2.12 KB
/
NegPosZero.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import java.util.Scanner; //import scanner
import java.util.ArrayList; //import arraylist
//date: september 13 2024
//name: bob wang, negposzero.java
//description: Write an application that inputs five numbers and determines and prints the number of negative, positive and zero numbers that were input.
//skills: classes, imports, arraylist, if statements, inputs, scanner package
class NegPosZero{
public static void main(String[]args) { //the main method
System.out.println("Enter 5 integers");
Scanner input=new Scanner(System.in); ///input
int number1,number2,number3,number4,number5;
number1=input.nextInt();
number2=input.nextInt();
number3=input.nextInt();
number4=input.nextInt();
number5=input.nextInt();
//declare variables
int positive=0;
int negative=0;
int zero=0;
//declare the arraylist
ArrayList<Integer> numberlist = new ArrayList<Integer>();
//adds input numbers to the arraylist
numberlist.add(number1);
numberlist.add(number2);
numberlist.add(number3);
numberlist.add(number4);
numberlist.add(number5);
//if statements to check every element of the arraylist
if (numberlist.get(0)==0) {
zero++;
}
else if (numberlist.get(0)<0) {
negative++;
}
else {
positive++;
}
if (numberlist.get(1)==0) {
zero++;
}
else if (numberlist.get(1)<0) {
negative++;
}
else {
positive++;
}
if (numberlist.get(2)==0) {
zero++;
}
else if (numberlist.get(2)<0) {
negative++;
}
else {
positive++;
}
if (numberlist.get(3)==0) {
zero++;
}
else if (numberlist.get(3)<0) {
negative++;
}
else {
positive++;
}
if (numberlist.get(4)==0) {
zero++;
}
else if (numberlist.get(4)<0) {
negative++;
}
else {
positive++;
}
System.out.printf(".\n There are this many positive numbers %d",positive); //prints out how many positive numbers
System.out.printf(".\n There are this many negative numbers %d",negative); //prints out how many negative numbers
System.out.printf(".\n There are this many zeroes %d",zero); //prints out how many zeroes
}
}