Question

In: Computer Science

Write a Racket function that will take a list of numbers as a parameter and return...

Write a Racket function that will take a list of numbers as a parameter and return true if they all are positive, and false otherwise. You are NOT required to check the type of elements in the list.

(please do on racket language)

Solutions

Expert Solution

solution:

import java.util.*;
public class Racket{

// racket method for return true if all the element in list are positive, and false otherwise.

static boolean racket(List<Integer> list){
for(int i=0; i<list.size(); i++){
if(list.get(i)<0) // Checking whether an element is positive or not
return false;
}
return true;
}  

public static void main(String args[]){
Scanner scan = new Scanner(System.in);
List<Integer> list = new ArrayList<>();
System.out.print("Enter the size of list : ");
int size = scan.nextInt(); // Store the size of list.
for(int i=0; i<size; i++){
list.add(scan.nextInt()); //Taking input in list/
}
System.out.println(racket(list)); // For printing the result.
}
}

Output :

#please consider my effort and give me a like...thank u....


Related Solutions

write a function that return a list of row numbers in matrix with removing the wrong...
write a function that return a list of row numbers in matrix with removing the wrong value. Ex: remove_row( matrix, wro) if matrix = [[5,2,8],[6,7,20],[10,25,9]] wro= 20 then output will be [1,2] Do not use any built in functions.
Problem: Grading Function #Write a function called getScore() that does not take any parameter. Inside the...
Problem: Grading Function #Write a function called getScore() that does not take any parameter. Inside the function, it asks the user to input scores for 3 items (Each of the items is out of 100). The final score is calculated by 20% of item1 + 30% of item2 + 50% of item3. After calculating the final score, the function returns it to the caller. The scores are floating-point numbers. #Write another function called getLetterGrade() that takes a float parameter and...
In this lab we will write 3 functions: GenData: This function will take an integer parameter...
In this lab we will write 3 functions: GenData: This function will take an integer parameter and return a vector with that many random integers generated in the range of 0 and 100 (rand()%101). Seed the random number generator with 22. Mean(): This function will take a vector and return the mean. Variance(): This function will take a vector and return the population variance, as: [Sum for values[( x_i - Mean )^2]] / (number of items) In Main: Use GenData...
Write a function that will take in an array (of type double), and will return the...
Write a function that will take in an array (of type double), and will return the array with all of the elements doubled. You must use pass-by-reference and addressing and/or pointers to accomplish this task. C++
Write a function which receives a list and returns a number. In the list, all numbers...
Write a function which receives a list and returns a number. In the list, all numbers have been repeated twice except one number that is repeated once. The function should return the number that is repeated once and return it.write a python program for this question. use main function.
6.15 LAB: JavaScript arrays Write the function divideArray() in script.js that has a single numbers parameter...
6.15 LAB: JavaScript arrays Write the function divideArray() in script.js that has a single numbers parameter containing an array of integers. The function should divide numbers into two arrays, evenNums for even numbers and oddNums for odd numbers. Then the function should sort the two arrays and output the array values to the console. Ex: The function call: var nums = [4, 2, 9, 1, 8]; divideArray(nums); produces the console output: Even numbers: 2 4 8 Odd numbers: 1 9...
Task 04: Running Average Write a function average that does not take any parameter and asks...
Task 04: Running Average Write a function average that does not take any parameter and asks the user to enter a positive number in a loop. The loop terminates when the user enters a negative number and the average is printed on the console. The function does not return any value. Save the function in a PyDev library module named functions.py Write a main program named t04.py that tests the function. Sample run: Enter a positive number: 2 Enter a...
PLEASE GIVE THE CODE IN RACKET PROGRAMMING RECURSIVE LANGUAGE ONLY Write a Racket function "combine" that...
PLEASE GIVE THE CODE IN RACKET PROGRAMMING RECURSIVE LANGUAGE ONLY Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates to a new function. Both f and g will be functions that take one parameter and evaluate to some result. The returned function should be the composition of the two functions with f applied first and g applied to f's result. For example (combine add1 sub1) should evaluate to a function equivalent to (define...
Write a Python program that calls a function to sum all the numbers in a list...
Write a Python program that calls a function to sum all the numbers in a list and returns the result to the caller. The main program creates a list (with hard-coded or user input) and passes the list as an argument to the function. You may not use the built-in function, sum. The program calls a second function to multiply all the numbers in a list passed to it by main and returns the product back to the caller. List...
#Write a function called find_max_sales. find_max_sales will #have one parameter: a list of tuples. Each tuple...
#Write a function called find_max_sales. find_max_sales will #have one parameter: a list of tuples. Each tuple in the #list will have two items: a string and an integer. The #string will represent the name of a movie, and the integer #will represent that movie's total ticket sales (in millions #of dollars). # #The function should return the movie from the list that #had the most sales. Return only the movie name, not the #full tuple. #Below are some lines of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT