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 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.
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 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...
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++
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT