Introduction to Array

Array indexes always begin with zero. The elements of an array are accessed using integer-valued indices. In Java, the first element of an array always has index zero. The length of an array is fixed at the time of its creation. An array represents related entities having same data type in contiguous or adjacent memory locations. The related data having data items form a group and are referred by the same name. To declare an array, write the data type, followed by a set of square brackets, followed by the identifier name. Elements of an array are accessed using their index values. Arrays have a length attribute which can be used for bounds checking. Whenever an array is accessed, the index is checked to ensure that it exists within the bounds of the array. The data type of array elements is known as the base type of the array.

To Access the full content, Please Purchase

  • Q1

    (a) What will be the output of each of the codes given below? Also, give reason for the same. [5]
    (i) int f=1, i=2;

    while (++i

    Marks:5
    Answer:

    5a (i) The output will be 12.

    The test expression of the while loop is evaluated before entering into the loop. Thus, the value of i for the first iteration becomes 3.

    In the first iteration, f becomes 1* 3, i.e., 3.

    So, before evaluating the test expression, i is incremented again and the loop is executed with i=4.

    f gets the value 3*4, i.e., 12.

    After i is incremented, the test expression of the while loop becomes false and the print statement prints 12.

    (ii) The output will be 24.

    The test expression of the do-while is executed first before exiting the loop. Thus, the value of i for the first iteration is 2. The loop is executed thrice for three values of i which are 2, 3 and 4. f gets the value of 1*2*3*4, which is 24.

    (b) public class student

    {

    public void factorial(intnum)

    {

    longi=0, fact=1;

    i=num;

    while(num!=0)

    {

    Fact=fact*num;

    --num;

    }

    System.out.println (“Factorial is” +fact);}

    public static void main(String[] args)

    studentobj=new student();

    obj. factorial(5);

    }

    }

    (c) No output. It is an infinite loop.
    Since the condition of a while loop is always true, hence it does not end.

    View Answer
  • Q2

    (a) Explain JVM and its role in running Java applications on any system.

    (b) For exercises a to e, consider the declarations below, then indicate the value that is assigned in each assignment statement. That is, show what is stored in the iResult, fResult, or sResult variables after each assignment. Show each floating point value to three places past the decimal point.

    intiResult, num1 = 25, num2 = 40,num3 = 17,num4=5;

    int num5 = -14, num6 = -27;

    doublefResult, val1 = 17.0, val2 = 12.78;

    String sResult, title = "Java Software Solutions";


    a. fResult = val1 / val2;
    b. iResult = num1 / num4;

    c. fResult = num1 / (double) num2;

    d. fResult = (int) ((double) num1 / num2);

    e. iResult = num2 % num3;

    Marks:5
    Answer:

    (a) JVM (Java virtual machine) is Java interpreter. It behaves like a virtual processor chip. Therefore, it was named Java Virtual Machine. Machine language of JVM is Java Byte code. It converts compiled Java byte code into machine code of the host system. A diagram showing the role of JVM in running Java applications

    (b)
    a.
    fResult = val1 / val2; 1.330
    b. iResult = num1 / num4; 5
    c. fResult = num1 / (double) num2; 0.625
    d. fResult = (int) ((double) num1 / num2); 0.0
    e. iResult = num2 % num3; 6

    View Answer
  • Q3

    Consider these propositions given below.

    A: It is raining.
    B: Wind is blowing.
    C: I am not driving.

    From these, create the following propositions.

    i) A v B

    ii)~B

    iii) ~A.C

    iv) A.~C

    v) A + B.C

    Marks:5
    Answer:

    i) A v B : It is raining OR wind is blowing.

    ii) ~B :Wind is NOT blowing.

    iii) ~A.C : It is NOT raining AND I am not driving.

    iv) A.~C : It is raining AND I am driving.

    v) A + B.C : It is raining OR wind is blowing AND I am not driving.

    View Answer
  • Q4

    (a) What are the uses of Adders in computer. Name the types of adders. [2]

    (b) Disjunctive is one of the connectives of propositional logic. Explain it [2]

    (c) Write instruction to load the accumulator with the data value F2H and save the data in register C. [2]

    (d) Write the function of LDA and SUB. [2]

    (e) Differentiate simple proposition and compound proposition. [2]

    Marks:10
    Answer:

    (a) An adder is a digital circuit that performs addition of numbers in the ALU of computer. These are used not only in the arithmetic logic unit(s) but also in other parts of the processor, where they are used to calculate addresses and table indices.

    The two types of adders are – i)Half Adder ii) Full Adder.


    (b) Disjunctive(OR) means one of the two arguments is true or both are true. It is represented by + or v.
    E.g., p+q ->p OR q
    This means either of the two is true or both are true.


    (c) MVI A, F2H : moves immediate value F2H into A register.
    MOV C, A: moves data from register A to register C.


    (d) LDA01 – The contents of the memory location, specified by a 16-bit address in the operand, are copied to the accumulator. The contents of thesource are not altered.
    SUB – The contents of the operands are subtracted from the contents of the accumulator and the result is stored in the accumulator.

    (e) The differences are as follows:-

    Simple Proposition

    Compound Proposition

    1. Does not contain any other proposition as a part

    1. Contains two or more simple propositions as parts

    2. Uses lower case letters(a, p, q, r etc.)

    2. Part of a larger proposition

    3. Example: It is raining.

    3. Example: If it’s raining, then take umbrella.

    View Answer
  • Q5

    (a) Define hexadecimal number system. [1]

    (b) Which ports are used to connect the graphics card? [1]

    (c) What is the purpose of the mvi instruction in 8085 microprocessor? [1]

    (d) Write any two features of GUI operating system. [1]

    (e) Illustrate the use of External Bus. [1]

    Marks:5
    Answer:

    (a) The hexadecimal number system(base 16) is composed of sixteen unique symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F.

    (b)AGP Ports are used to connect the graphics card.

    (c) MVI is used to transfer immediate data to a register or a memory location.

    (d)Desktop and Window are two features of GUI operating system.

    (e)External buses are used for connecting the various peripheral devices like secondary memory devices, I/O units etc. with the motherboard (with CPU).

    View Answer