Page 396 - ComputerScience_Class_11
P. 396

3.  import java.util.Scanner;
                    public class LinearSearchExample {
                        public static void main(String[] args) {
                            Scanner sc = new Scanner(System.in);
                            int[] numbers = {10, 20, 30, 40, 50};  // Fixed input
                            int searchNum = 30;  // Fixed search number
                            int pos = -1;
                            for (int i = 0; i < numbers.length; i++) {
                                if (numbers[i] == searchNum) {
                                    pos = i;
                                    break;
                                }
                            }
                            if (pos != -1) {
                                System.out.println(searchNum + " found at position " + (pos + 1));
                            } else {
                                System.out.println(searchNum + " not found");
                            }
                        }
                    }
              H.  Unsolved Programs:
                  1.  Write a Java program to input 10 positive and negative numbers each and calculate the following:
                     a.  sum of odd numbers in an array
                     b.  product of all the multiples of 7.
                  2.  Write a Java program to input 20 names in an array and print the names in ascending order using the bubble sort method.
                  3.  Write a Java program to store 25 numbers in a single-dimensional array and arrange them in descending order by using insertion
                    sort.
                  4.  Write a Java program to input 10 numbers and print the prime numbers only.
                  5.  Write a Java program to create an array of 5 elements and using switch case do the following.
                     Case 1: prints the sum of all the prime numbers
                     Case 2: print all the odd negative numbers
                  6.  Write a Java program to create an array of size 2 × 3 and print the factorial of all the numbers separately.
                  7.  Write a Java program to accept  the item names and prices of some items in two single-dimensional arrays and calculate the total
                    amount to be paid by the customer. Display in the following manner:

                      Item Name      Price
                          –            –
                          –            –
                     Total Amount      –

                  8.  Write a Java program to input "n" numbers and store the odd numbers and even numbers separately in two different arrays.
                  9.  Write a Java program to accept the names and marks in computer science of forty students in an array and then print the names
                    and marks of students according to their merit.
                 10.  Write a Java program to find the common elements between two arrays A and B and print them.
                 11.  Write a Java program that reads the following list of countries and their respective cities into two separate one-dimensional
                    arrays. The program should accept the name of a country as input and give the name of the corresponding city as an output.
                    The  program  should  display  an  error  message  when  the  user  enters  the  country  which  is  not  mentioned  in  the  given  list.
                    To stop the program, "XXX" is to be entered as input.



                  394  Touchpad Computer Science (Ver. 3.0)-XI
   391   392   393   394   395   396   397   398   399   400   401