Lab 3 – Pseudocode and Parallel Arrays
This lab requires you to think about the steps that take place in a program by writing pseudocode. Read the following program prior to completing the lab.
Design an application in which the number of days for each month in the year is stored in an array. (For example, January has 31 days, February has 28, so on. Assume that the year is not a leap year.) Also, use a parallel array to store the month names. Display 12 sentences in the same format; for example, the first sentence is January has 31 days..
For the programming problem, create the pseudocode and enter it below.
Enter pseudocode here
Kindly
upvote if this helped
Pseudo-code
days [] = {31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31
, 30 , 31};
months [] = {"January" , "Febuary" , "March" ,
"April" , "May" , "June" , "July" , "August" , "September" ,
"October" , "November" , "December"};
i = 0;
for i <- 12
print ( months [i] +" has "+days[i]+" days" );
i++;
end loop
OUTPUT
Corresponding java code for better understanding:
public class Months {
public static void main(String[] args) {
int days [] = {31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31};
String months [] = {"January" , "Febuary" , "March" , "April" , "May" , "June" , "July" , "August" , "September" , "October" , "November" , "December"};
for(int i=0;i<=11;i++) {
System.out.println(months[i]+" has "+days[i]+" days");
}
}
}
Get Answers For Free
Most questions answered within 1 hours.