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 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.
write a javascript function called cal_modes that will take a List of numbers or strings as...
write a javascript function called cal_modes that will take a List of numbers or strings as input and returns a List of the most frequent values. If there's only one most-frequent value, it returns a single-element List. example cal_modes([3,4,5,5]) should return [5] cal_modes([8.9, 1, 1]) should return [1] cal_modes([2.5, -2, -2, 2.5]) should return [2.5] cal_modes([3,3,4,4]) should return [3,4] cal_modes([3,4,5]) should return [3,4,5], because all occur with equal frequency cal_modes(["hi", "what", "where", "hi"]) should return ["hi”]
RACKET a) Write a recursive function (gen-list start end). This function will generate a list of...
RACKET a) Write a recursive function (gen-list start end). This function will generate a list of consecutive integers, from start to end. If start > end then an empty list is generated. For example: (gen-list 1 5) ---> (1 2 3 4 5) b) write a recursive function pair-sum? that takes an integer sequence as generated by the gen-list function in exercise 4 above. This function tests whether any two adjacent values in the given list sum to the given...
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.
Write a function in C# that takes an array of double as the parameter, and return...
Write a function in C# that takes an array of double as the parameter, and return the average
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a function that will accept a list of numbers and an integer (n). The function...
Write a function that will accept a list of numbers and an integer (n). The function should return a list containing every nth item from the input list, always starting with the first item in the list. The original list should not be modified. For example, if the function is passed the list [8, 3, 19, 26, 32, 12, 3, 7, 21, 16] and the integer 3, it will return the list [8, 26, 3, 16] If the function is...
Write in Racket Language Write a recursive Racket function "all-same" that takes a string as a...
Write in Racket Language Write a recursive Racket function "all-same" that takes a string as a parameter and evaluates to true iff every character in the string is the same. Note: A string of length 0 or 1 should also evaluate to true.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT