├── 03- 07-2023 └── README.md /03- 07-2023: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class TaxCalculator { 4 | public static void main(String[] args) { 5 | Scanner scanner = new Scanner(System.in); 6 | 7 | System.out.print("Enter the monthly salary: "); 8 | double monthlySalary = scanner.nextDouble(); 9 | double annualSalary = monthlySalary * 12; 10 | double tax = 0.0; 11 | if (annualSalary <= 250000) { 12 | // No tax 13 | tax = 0.0; 14 | } else if (annualSalary <= 500000) { 15 | // 10% tax 16 | tax = 0.1 * (annualSalary - 250000); 17 | } else if (annualSalary <= 1000000) { 18 | // 20% tax 19 | tax = 0.2 * (annualSalary - 500000) + 25000; 20 | } else if (annualSalary <= 10000000) { 21 | // 30% tax 22 | tax = 0.3 * (annualSalary - 1000000) + 125000; 23 | } else { 24 | // 30% tax for 1 crore 25 | tax = 0.3 * (annualSalary - 1000000) + 125000; 26 | } 27 | 28 | System.out.println("Annual Salary: " + annualSalary); 29 | System.out.println("Tax: " + tax); 30 | } 31 | } 32 | ........................................................................................................................ 33 | public class LinearSearch { 34 | public static int linearSearch(int[] arr, int target) { 35 | for (int i = 0; i < arr.length; i++) { 36 | if (arr[i] == target) { 37 | return i; 38 | } 39 | } 40 | return -1; 41 | } 42 | public static void main(String[] args) { 43 | int[] arr = {5, 8, 2, 10, 3, 1}; 44 | int target = 10; 45 | 46 | int index = linearSearch(arr, target); 47 | if (index != -1) { 48 | System.out.println("tgt found at index: " + index); 49 | } else { 50 | System.out.println("tgt not found"); 51 | } 52 | } 53 | } 54 | 55 | ............................................................................................................................ 56 | 57 | // linear search on sorted array 58 | 59 | public class LinearSearch { 60 | public static int linearSearchSorted(int[] arr, int target) { 61 | for (int i = 0; i < arr.length; i++) { 62 | if (arr[i] == target) { 63 | return i; 64 | } else if (arr[i] > target) { 65 | return -1; 66 | } 67 | } 68 | 69 | return -1; 70 | } 71 | 72 | public static void main(String[] args) { 73 | int[] arr = {1, 2, 3, 5, 8, 10}; 74 | int target = 5; 75 | 76 | int index = linearSearchSorted(arr, target); 77 | if (index != -1) { 78 | System.out.println("Target found at index: " + index); 79 | } else { 80 | System.out.println("Target not found"); 81 | } 82 | } 83 | } 84 | ......................................................................................................................... 85 | 86 | // binary search 87 | 88 | public class BinarySearch { 89 | public static int binarySearch(int[] arr, int target) { 90 | int left = 0; 91 | int right = arr.length - 1; 92 | 93 | while (left <= right) { 94 | int mid = left + (right - left) / 2; 95 | 96 | if (arr[mid] == target) { 97 | return mid; 98 | } else if (arr[mid] < target) { 99 | left = mid + 1; 100 | } else { 101 | right = mid - 1; 102 | } 103 | } 104 | 105 | return -1; 106 | } 107 | 108 | public static void main(String[] args) { 109 | int[] arr = {1, 2, 3, 5, 8, 10}; 110 | int target = 5; 111 | 112 | int index = binarySearch(arr, target); 113 | if (index != -1) { 114 | System.out.println("Target found at index: " + index); 115 | } else { 116 | System.out.println("Target not found"); 117 | } 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # prolifics-java-assignment --------------------------------------------------------------------------------