Arrays-Learning Java Language-Assignment, Exercises of Java Programming

This assignment is for Learning Java Language course by Suryavanshi Vikram at Cochin University of Science and Technology. It includes: Declare, Integer, Arrays, Sizes, Elements, Sample, Character, Index, search, Contents

Typology: Exercises

2011/2012

Uploaded on 07/12/2012

yumna
yumna 🇮🇳

4.8

(4)

12 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Assignment: 01
Deadline: 21st Feb. 2012
1. Declare two integer arrays of sizes 10 each. Your task is to print the elements which are
common in both the arrays.
Sample Input:
a[]: 1,2,3,4,5,6,7,8,9,20
b[]: 2,4,6,8,10,12,14,16,18,20
Sample Output:
Common elements: 2, 4, 6, 8, 20
2. Write a program which will take a character array a[] of size 15 and a character array b[] of size
10 from the user. Also take an index from the user, and starting from the given index place array
b[] in array a[]. At the end, display a[].
Sample Input:
a[]: program
b[]: computer
Index: 3
Sample Output:
a[]: procomputer
3. Declare a character array A[] of size 15 and B[] of size 10. Take input in both the arrays. Your
task is to search the contents of array B[] in array A[].
Sample Input: A[ ] = helloworld B[ ] = hello
Sample Output: Word found
Sample Input: A[ ] = helloworld B[ ] = good
Sample Output: Word not found
4. Declare a character array of size 20. Take input in the array (including spaces). Your task is to
capitalize 1st letter of each word, and if the first letter is already a capital letter then replace the
3rd letter with @.
Sample Input: Hello world
Sample Output: He@lo World
Docsity.com
pf2

Partial preview of the text

Download Arrays-Learning Java Language-Assignment and more Exercises Java Programming in PDF only on Docsity!

Assignment: 01

Deadline: 21st^ Feb. 2012

  1. Declare two integer arrays of sizes 10 each. Your task is to print the elements which are common in both the arrays. Sample Input: a[] : 1,2,3,4,5,6,7,8,9, b[]: 2,4,6,8,10,12,14,16,18, Sample Output: Common elements: 2, 4, 6, 8, 20
  2. Write a program which will take a character array a[] of size 15 and a character array b[] of size 10 from the user. Also take an index from the user, and starting from the given index place array b[] in array a[]. At the end, display a[]. Sample Input: a[] : program b[]: computer Index: 3 Sample Output: a[]: procomputer
  3. Declare a character array A[] of size 15 and B[] of size 10. Take input in both the arrays. Your task is to search the contents of array B[] in array A[]. Sample Input: A[ ] = helloworld B[ ] = hello Sample Output: Word found Sample Input: A[ ] = helloworld B[ ] = good Sample Output: Word not found
  4. Declare a character array of size 20. Take input in the array (including spaces). Your task is to capitalize 1st^ letter of each word, and if the first letter is already a capital letter then replace the 3 rd^ letter with @. Sample Input: Hello world Sample Output: He@lo World

Docsity.com

  1. Write a program which will take four small alphabets from the user in main(). Pass these alphabets to a function alphabetical_order(). The function alphabetical_order() will print the given alphabets in alphabetical order. Characters ASCII Values a – z 97 – 122 Sample Input: f , a , n, s Sample Output: a f n s
  2. Write a program which will declare an array A of size 10. Ask the user to enter values in the array. Each input must be a three digit number. Your task is to calculate the sum of all the digits present in the array. At the end, display the sum. Sample Input: 111,222,333,444,555,666,777,888,999, Sample Output: Sum is 135.
  3. Write a program in which you have two 2-dimensional arrays. Both the arrays will have digits from 1 to 9 stored in them. If any element of 1st^ array is a multiple of 2, replace it with 1, otherwise replace it with zero. Count how numbers in the first array are multiples of 2. Also display those numbers. Similarly if any element of 2nd^ array is a multiple of 3, replace it with 1, otherwise replace it with zero. Count how numbers in the second array are multiples of 3. Also display those numbers and both arrays.
  4. Create a calculator with well defined operations. Also provide proper menu for the program.
  5. Design and implement the following program with user friendly menu: a. Get student’s personal information (Name, reg No: NIC, semester, program) of whole ACP class and store it in an array of students. b. Provide facility to search the student based on varied criterion. c. Your program should be able to list down all the students in same semester or program.

Docsity.com