alright so my question is probably stupid and I don't even know if it can be done but I have inserted some elements into an array through scanner, and I have put it through a certain calculation . The calculation results are also stored inside another array. what I want to do is to see if these calculated values are larger than 0. I want these calculated values to be printed along side the + or - sign. so what I was thinking is to have 2 sets of printing statements where if the sign value of the calculated amount is >0 it will proceed a print statement where as if it is <0 it will proceed another print statement. But I don't know how to check if a element inside array is larger or smaller than zero. Spare my explanation I tried my best to not make it hard to understand.
so lets say the user inputs 14. which would then go through the calculation process and store 2 inside the array.[(14-10)/2]. so since this is bigger than zero , i want a print statement to execute in a way that i can get +2 as the answer.
assume the user enters 8. which would go through the calculation process and store -2[(8-10)/2], and since -2 is stored here it is <0 and there for i want a separate statement to get executed.
My issue is i dont know how to check if a element inside an array is 0 or not. there are 5 elements inside the array and i want to check if all of them are above or below zero and print different statements for each. thank you so much in advance.I am using java btw.
int[] bonus=new int[6]; // this is used to store the keyboard entries
if(bonus[]<0) { //used this to check the condition and if the conditon
System.out.println(level);
System.out.println("your str=" + bonus[0]);
else{System.out.println("your str=+" +bonus[0]);
}
bonus is the arrayName i have used and 0 is the first slot in which the value entered through keyboard for str is stored after the calculation process.Note:there are few coding prior to that including the array executions which i have not stated hoping this would be enough
I managed to get through this using a for loop i and iterating through it i managed to check if they were 0 and/or above .Thank you for those who read and tried to go through this
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments