Java Programming Exercises for Students
Java Programming Exercises for Students
To calculate investments, create a nested loop structure to evaluate the formula V = P (1 + r)^n for varying values of P (ranging from 1000 to 10000 in increments of 1000), r (from 0.10 to 0.20), and n (from 1 to 10). Compute V for each combination and display the results in a table format .
To handle sales data, use a double-subscripted array "sales" where rows represent products and columns represent salespeople. Input data contains entries with salesperson number, product number, and sale amount. Update the "sales" array accordingly. After all data is processed, compute row totals (total sales per product) and column totals (total sales per salesperson). Print the table showing these figures, including cross totals at the edges of the table .
To categorize students' marks into different ranges, you should first acquire the number of students and their respective marks. Then, initialize counters for each category range: 81-100, 61-80, 41-60, and 0-40. Loop through the list of marks, incrementing the appropriate counter based on each student's marks. Finally, print out the count of students in each range .
Identifying maximum elements requires iterating over each element [i, j] in the array, verifying it is the largest in its row and column. For a thorough check, loop through the i-th row and j-th column of each element, comparing with the element to ensure it is the maximum in both directions .
The equivalent resistance of resistors in parallel is found by taking the inverse of the sum of the inverses of each resistor's resistance: 1/R_eq = 1/R1 + 1/R2 + ... + 1/Rn. To program this, take input for the resistances, compute the sum of their inverses, and then find the inverse of that sum to get the equivalent resistance. This method can be extended to any number of resistors .
To determine eligibility for a professional course, students must meet specific criteria based on their marks: Mathematics >= 60, Physics >= 50, Chemistry >= 40, with either the total marks for all subjects >= 200 or the combined total for Mathematics and Physics >= 150. A program should input each student's marks, check against these conditions, and list candidates who satisfy the eligibility criteria .
The straight-line method calculates depreciation as depreciation = (purchase price - salvage value) / years of service. To find the salvage value, rearrange this formula: salvage value = purchase price - (depreciation * years of service). A program should input the purchase price, years of service, and annual depreciation to solve for the salvage value .
To merge two sorted arrays (A & B) into one sorted array (C), use two pointers to track the current index of A and B. Compare elements at these indices, and append the smaller element to C, advancing the pointer of the array from which the element was taken. Continue until all elements from both arrays have been included in C .
Calculating frequency variations involves the formula: frequency = √((1 / LC) - (R²/4C²)). To program this, set the variables L and R. Loop through values of C from 0.01 to 0.1 in increments of 0.01, compute the frequency for each, and output the results .
To process electoral votes, read each ballot's candidate number (ranging from 1 to 5). Use an array 'count' to increase the number of votes for a valid candidate number while incrementing a separate counter for any number outside this range (spoilt ballots). This ensures all votes and errors are correctly reflected in the final count .