mercredi 28 février 2018

how to check if a value inside an array is larger than a certain value

alright so my question is probably stupid and i dont 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 dont 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.

Aucun commentaire:

Enregistrer un commentaire