You are viewing our Forum Archives. To view or take place in current topics click here.
Java Array help needed.
Posted:

Java Array help needed.Posted:

BPM
  • Gold Gifter
Status: Offline
Joined: Sep 12, 201013Year Member
Posts: 7,232
Reputation Power: 1137
Status: Offline
Joined: Sep 12, 201013Year Member
Posts: 7,232
Reputation Power: 1137
Still learning Java. I have another 'easy' question which I can't seem to do. I don't know how to to start it. I tried looking tutorials online but they seem so different to the notes I have from class. I kinda have an idea but I don't know how to transfer what I am thinking to practice

Question 1
Suppose that the following temperature measurements (in centigrade) were made at
midnight over a 14 day period in the car park of the Campus.
[12, 3, 9, -2, 8, 2, 15, -3, 7, -1, 9, 4, 14, 5]
Write a program called Temperature that will create and initialise an array containing the
temperatures listed above and which will print the number of nights when the
temperature was freezing (<1) and number of nights when the temperature was over 10
degrees. (Hint use an array initialiser list to create and initialise the array).

Could someone push me in the correct path or something
#2. Posted:
speed
  • Summer 2019
Status: Offline
Joined: Jun 11, 200914Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Status: Offline
Joined: Jun 11, 200914Year Member
Posts: 9,897
Reputation Power: 3160
Motto: "I'l no I grew up to fast speed I no u will be little famous" - Famous_Energy
Basically you just need to loop through an array with a conditional statement.

You'll need 2 int variables to store the counts for "> 10" and "< 1".

You'll loop through the array, and if each value matches one of the conditions, you'll increment the respective int you created above.

Finally you'll just print out the values of the two variables.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.