IsNegative.java
This program was created once again using the old school Java GUI known as JOptionPane.
Unfortunately, the name of this program should’ve been return negative. Apologies for the confusion!
It checks if the number is negative and if not, make it negative.
The code has been modified slightly and now uploaded to the site.
JOptionPane Code Snippet
//Link: https://edabit.com/challenge/b3wgTSBnd2HH44qzr
import javax.swing.JOptionPane;
public class IsNegative {
public static void main(String[] args){
boolean looper = true;
JOptionPane.showMessageDialog(null, "Welcome!\nPlease press enter to continue...");
while (looper == true){
String input = JOptionPane.showInputDialog(null, "Please type your number here to convert to negative!\nYou must type in a number in order to exit!");
int get = Integer.parseInt(input);
int result = returnNegative(get);
String input2 = JOptionPane.showInputDialog(null, "Loading...\nYour number is: " + result + "\nType -1 to exit or type any number to continue!");
int get2 = Integer.parseInt(input2);
if (get2 == -1){
System.exit(0);
}
else if (get2 < -1 || get2 > -1){
looper = true;
}
}
}
public static int returnNegative(int n){
if (n >= 1){
n = n * -1;
return n;
}
else if (n == 0){
return 0;
}
else{
JOptionPane.showMessageDialog(null, "The number is already negative!");
System.exit(1);
return n;
}
}
}