Skip to main content

ads1

Class 12th Chapter 9 Working with Array and String

An array is a variable representing a collection of homogeneous type of elements.
Arrays are useful to represent vector, matrix and other multi-dimensional data.
Vector is a one dimensional (1-D) data structure that can be used to store list of items like characters, numbers.

Arrays are useful when same operations are to be performed on various elements of the similar type.

Creating an array is a two step process:
1. Declare an array object

2. Create an array object An array object can be created in two ways:

1. Using new operator and specifying the size
2. Directly initializing the content of array  

To declare a 1-D array we use a pair of square brackets [ ] after array name or after data type.


 Choose the most appropriate from those given below :

(1) Which of the following refer to the starting index value in arrays ?

(a) 0
(b) 1
(c) null
(d) All of these

(2) What is the size of second dimension in an array sales[5][12] ?

(a) 5
(b) 12
(c) 60
(d) 10

(3) What will expression sales.length return for an array sales[5][12] ?

(a) 5
(b) 12
(c) 60
(d) 120

(4) When an array sales [5][12] is declared without specifying initial values, what is the initial value of sales[0][0] ?

(a) 0
(b) default value
(c) compilation error
(d) 60

(5) What does 'length' refer to for an object of String class ?

(a) attribute
(b) method
(c) class variable
(d) class name

(6) If 'str' is the object of String class and its content is "Thank GOD", then what is the value of str.length() ?

(a) 9
(b) 10
(d) 11
(c) 8

(7) What type of value is returned when we use get method of Calendar class with constant DAY_OF_WEEK as an argument ?

(a) int
(b) char
(c) String
(d) boolean


 
 

ads2

Popular posts from this blog

11. Write a Java program to input basic salary of an employee and calculate its Gross salary according to following:

    11. Write a Java program to input basic salary of an employee and calculate its Gross salary according to following: Basic Salary <= 10000 : HRA = 20%, DA = 80% Basic Salary <= 20000 : HRA = 25%, DA = 90% Basic Salary > 20000 : HRA = 30%, DA = 95% Static Solution :-  class salary {     public static void main(String args[])     {     double basic=20000.50,gross,da,hra;     if(basic <=10000)     {         da = basic * 0.8;         hra = basic *0.2;     }              else if(basic <=20000)     {         da = basic * 0.9;         hra = basic *0.25;     }     else     {         da = basic * 0.95;         hra = basic * 0.3;     }     gross = basic + da + hra;     System.out.println("The Gross Salary is :-"+gross);     } } Output :-  Dynamic Solution :-  class salary {     public static void main(String args[])     {     double basic=20000.50,gross,da,hra;     Scanner in = new Scanner(System.in);     System.out.println("Enter the Basic Salary

1. Given the school result data, analyses the performance of the students on #different parameters, e.g subject wise or class wise.

1. Given the school result data, analyses the performance of the students on #different parameters, e.g subject wise  or class wise. Solution :-   # x-axis is shows the subject and y -axis # shows the markers in each subject # import pandas and matplotlib  import pandas as pd  import matplotlib.pyplot as plt # Simple Line Chart with setting of Label of X and Y axis, # title for chart line and color of line  subject = ['Physic','Chemistry','Mathematics', 'Biology','Computer'] marks =[80,75,70,78,82] # To draw line in red colour plt.plot(subject,marks,'r',marker ='*')     # To Write Title of the Line Chart plt.title('Marks Scored') # To Put Label At Y Axis plt.xlabel('SUBJECT')           # To Put Label At X Axis plt.ylabel('MARKS')             plt.show() Output :- 

24.Create a Data Frame quarterly sales where each row contains the item category, item name, and expenditure. Group the rows by the category and print the total expenditure per category.

24.Create a Data Frame quarterly sales where each row contains the item category, item name, and expenditure. Group the rows by the category and print the total expenditure per category. import pandas as pd  # initialize list of lists data = [['CAR','Maruti',1000000],['AC','Hitachi',55000],['AIRCOLLER','Bajaj',12000], ['WASHING MACHINE','LG',15000],['CAR','Ford',7000000],['AC','SAMSUNG',45000],['AIRCOLLER','Symphony',20000],['WASHING MACHINE','Wirlpool',25000]] Col=['itemcat','itemname','expenditure'] # Create the pandas DataFrame qrtsales = pd.DataFrame(data,columns=Col) # print dataframe.  print (qrtsales) qs=qrtsales.groupby('itemcat')  print('Result after Filtering Dataframe')  print(qs['itemcat','expenditure'].sum()) Output :-