-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathposNeg.java
More file actions
46 lines (42 loc) · 1.08 KB
/
Copy pathposNeg.java
File metadata and controls
46 lines (42 loc) · 1.08 KB
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
/*
Given 2 int values, return true if one is negative and one is
positive. Except if the parameter "negative" is true, then
return true only if both are negative.
*/
package codingbat;
import java.util.*;
public class posNeg {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num1, num2, flag = 0;
System.out.println("Enter two integers: ");
num1 = sc.nextInt();
num2 = sc.nextInt();
if(num1 > 0){
if(num2 < 0){
flag = 1;
}
}
if(num2 > 0){
if(num1 < 0){
flag = 2;
}
}
if(num1 > 0){
if(num2 > 0){
flag = 3;
}
}
if(num1 < 0){
if(num2 < 0){
flag = 4;
}
}
if(flag == 1 || flag == 2 || flag == 4){
System.out.println("Negative!");
}
else{
System.out.println("Positive!");
}
}
}