how to make a program (java language) determining positive and negative numbers?
you will enter a number. ( for example 5 different numbers) others are postive and others are negative. how the systems determined that numbers. the program must be in a class form of java program. pls answer me
Answers:
import java.io.IOException;
public class PosNeg {
public static void main(String[] args) {
int [] wNumbers;
wNumbers = new int[5];
char c = ' ';
for (int i=0;i<5;i++) {
System.out.print("Enter the #"+i+": ");
try {
wNumbers[i]=System.in.read()-4...
if (wNumbers[i]<0)
wNumbers[i]=(System.in.read()-...
while (System.in.read()!='\n'){
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.print("The number you entered is ");
if (Math.abs(wNumbers[i])!=wNumbe...
System.out.println("negative."...
else
System.out.println("positive."...
}
}
}
Other answers:
try comparing the absolute value of the number. If it is equal, then it is positive otherwise, it is negative.
Hint: Try the abs method of Math.