In: Computer Science
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)
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....