Lists and Procedures Pseudocode Practice
For each situation, provide a pseudocoded algorithm that would accomplish the task. Make sure to indent where appropriate.
Situation A
Write a program that:
Takes the list lotsOfNumbers and uses a loop to find the sum of all of the odd numbers in the list (hint: use Mod).
Displays the sum.
Situation B
Write a procedure that takes a positive integer as a parameter. If the number given to the procedure is no more than 30, the procedure should return the absolute difference between that number and 30. If the number is greater than 30, the procedure should return the number doubled.
Examples:
difference30(13) → 17
difference30(46) → 92
difference30(30) → 0
Situation C
Write a procedure ConvertToBinary that takes an input as a number from 0 to 16 (including 0 but not 16) and converts it to a binary number. The binary number should be returned as a list

See Answers (1)

Accepted Answer

A program that takes the list of numbers and uses a loop to find the sum of all of the odd numbers in the list is given below:The Programimport java.util.*;public class Main{public static void main(String[] args) { //create a list with some numbers    List<Integer> lotsOfNumbers = Arrays.asList(7, 20, 1002, 55, 406, 99); //initialize the sum as 0    int sumOfOdds = 0;    //create a for each loop to iterate over the lotsOfNumbers list    //check each number, if it is odd or not using the mod    //if it is odd, add the number to the sum (cumulative sum)    for (int number : lotsOfNumbers){        if(number % 2 == 1)            sumOfOdds += number;    }    //print the sum    System.out.println("The sum of odd numbers: " + sumOfOdds);}}Read more about programming here:https://brainly.com/question/19054224#SPJ1

Related Question in Computers and Technology