Datasets:
ArXiv:
License:
Stack-Repo / data /train /akash-coded /FSD_Java /Lesson-5 /Linear Search /Assisted Practice Problem /LinearSearch.java
Download data/train/akash-coded/FSD_Java/Lesson-5/Linear Search/Assisted Practice Problem/LinearSearch.java from RepoFusion/Stack-Repo: direct link, hf CLI and curl.
- Browser
- Download file 639 Bytes
-
https://huggingface.co/datasets/RepoFusion/Stack-Repo/resolve/bbc90aef76314892f2d54f85da32b81503fb7eb3/data/train/akash-coded/FSD_Java/Lesson-5/Linear%20Search/Assisted%20Practice%20Problem/LinearSearch.java
- Command line
-
hf download 'hf://datasets/RepoFusion/Stack-Repo@bbc90aef76314892f2d54f85da32b81503fb7eb3/data/train/akash-coded/FSD_Java/Lesson-5/Linear Search/Assisted Practice Problem/LinearSearch.java'
-
curl -L -o LinearSearch.java https://huggingface.co/datasets/RepoFusion/Stack-Repo/resolve/bbc90aef76314892f2d54f85da32b81503fb7eb3/data/train/akash-coded/FSD_Java/Lesson-5/Linear%20Search/Assisted%20Practice%20Problem/LinearSearch.java
639 Bytes
| public class LinearSearch { | |
| public static void main(String[] args) { | |
| int[] arr = { 10, 20, 30, 40, 50 }; | |
| int searchValue = 40; | |
| int result = linearing(arr, searchValue); | |
| if (result == -1) { | |
| System.out.println("Element not in the array"); | |
| } else { | |
| System.out.println("Element found at index " + result + " and the search key is " + arr[result]); | |
| } | |
| } | |
| public static int linearing(int[] arr, int x) { | |
| for (int i = 0; i < arr.length; i++) { | |
| if (arr[i] == x) { | |
| return i; | |
| } | |
| } | |
| return -1; | |
| } | |
| } | |