fork download
  1. public class LinearSearch {
  2. public static void mainMethod(Integer key) {
  3. Integer[] arr = new Integer[]{5, 10, 15, 20, 25};
  4. Boolean found = false;
  5.  
  6. for (Integer i = 0; i < arr.size(); i++) {
  7. if (arr[i] == key) {
  8. System.debug('Element found at index: ' + i);
  9. found = true;
  10. break;
  11. }
  12. }
  13.  
  14. if (!found) {
  15. System.debug('Element not found.');
  16. }
  17. }
  18. }
Success #stdin #stdout #stderr 0.02s 9068KB
stdin
Standard input is empty
stdout
Object: UndefinedObject error: did not understand #LinearSearch
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
UndefinedObject class(Object)>>doesNotUnderstand: #LinearSearch (SysExcept.st:1448)
UndefinedObject>>executeStatements (prog:1)
stderr
./prog:2: parse error, expected '}'
./prog:14: expected expression