NestedForLoop

 Topic : Nested For Loop

class nestedloops

{

    public static void main()

    {

        int i,j;

        for (i=1;i<=2;i++)

        {

            for(j=1;j<=5;j=j+2)

            {

                System.out.println("i ="+i+" j ="+j);

            }

        }

    }

}

 

class nestedloops2

 {

    public static void main()

    {

        int i,j;

        for (i=14;i>=10;i=i-2)

        {

            for(j=9;j>=1;j=j-4)

            {

                System.out.println("i ="+i+" j ="+j);

            }

        }

    }

}

 Topic Nested For Loop: Pattern

/*

 * WAP to get the following output:

        *

        **

        ***

 */

 

 class floydTriangle

{

    public static void main()

    {

        int i,j;

        for (i=1;i<=3;++i)      //rows

        {

            for(j=1;j<=i;j++)   //column

            {

                System.out.print("*");

            }

            System.out.println();

        }

    }

}

/*

 * WAP to get the following output:

        ****

        ***

        **

        *

 */

 

 class InvertedTriangle

{

    public static void main()

    {

        int i,j;

        for (i=1;i<=4;++i)      //rows

        {

            for(j=4;j>=i;j--)   //column

            {

                System.out.print("*");

            }

            System.out.println();

        }

    }

}

/*

 * WAP to get the following output:

        4321

        432

        43

        4

 */

 

 class invertedNum

{

    public static void main()

    {

        int i,j;

        for (i=1;i<=4;++i)      //rows

        {

            for(j=4;j>=i;j--)   //column

            {

                System.out.print(j);

            }

            System.out.println();

        }

    }

}

 

/*

 * WAP to get the following output:

        5

        54

        543

        5432

        54321

 */

 

 class triangleNum

{

    public static void main()

    {

        int i,j;

        for (i=5;i>=1;--i)      //rows

        {

           

            for(j=5;j>=i;j--)   //column

            {

                System.out.print(j);

               

            

            }

            System.out.println();

        }

    }

}

 

/*

 * WAP to get the following output:

        5

        5   4

        5   4   3

        5   4   3   2

        5   4   3   2   1

 */

 

 class triangleNumwithSpace

{

    public static void main()

    {

        int i,j;

        for (i=5;i>=1;--i)      //rows

        {

           

            for(j=5;j>=i;j--)   //column

            {

                System.out.print(j +"\t");

               

            

            }

            System.out.println();

        }

    }

}

/*

 * WAP to get the following output:

     ****

     ****

     ****

*/

 class squareSymbol

{

    public static void main()

    {

        int i,j;

        for (i=1;i<=3;i++)      //rows

        {

            for(j=1;j<=4;j++)   //column

            {

                System.out.print("*");

            }

            System.out.println();

        }

    }

}

 

/*

 * WAP to get the following output:

5

54

543

5432

54321

*/

 

 class nestedloop4

{

    public static void main()

    {

        int i,j;

        for (i=5;i>=1;--i)      //rows

        {

            for(j=5;j>=i;--j)   //column

            {

                System.out.print(j);

            }

            System.out.println();

        }

    }

}

 

/*

 * WAP to get the following output:

    A

    AB

    ABC

    ABCD

    ABCDE

A=65 to Z=90

a=97 to z=122

*/

 

 class nestedloop5

{

    public static void main()

    {

        int i,j;

        for (i=65;i<=69;i++)      //rows

        {

            for(j=65;j<=i;j++)   //column

            {

                System.out.print((char)j);

            }

            System.out.println();

        }

    }

}

 

/*

 * WAP to accept number of lines of floyd triangle required

 * and accordingly display the output.

 * for example the user enter 5, five lines of floyd triangle are:

 *

        1

        23

        456

        78910

        1112131415

 */

import java.util.Scanner;

 class floydTriangleReq

{

    public static void main()

    {

        int i=1,j,c=i,n;

        Scanner ob=new Scanner(System.in);

        System.out.println("Enter no. of lines floyd triangle required:");

        n=ob.nextInt();

        System.out.println("_____Output______");

        for (i=1;i<=n;i++)      //rows

        {

            for(j=1;j<=i;j++)   //column

            {

                System.out.print(c);

                c++;

            }

            System.out.println();

        }

    }

}

 

/*

 * WAP to get the following output:

    10  9    8   7

    6   5   4

    3   2

    1

  

*/

 

 class nestedloop7

{

    public static void main()

    {

        int i,j,c=10;

        for (i=4;i>=1;i--)      //rows

        {

            for(j=1;j<=i;j++)   //column

            {

                System.out.print(c+"\t");

                c--;

            }

            System.out.println();

        }

    }

}

 

/*

 * WAP to get the following output:

    *

    *#

    *#*

    *#*#

    *#*#*

   

*/

 

 class nestedloop8

{

    public static void main()

    {

        int i,j;

        for (i=1;i<=5;i++)      //rows

        {

            for(j=1;j<=i;j++)   //column

            {

                if(j%2==0)

                {

                    System.out.print("#");

                }

                else

                {

                    System.out.print("*");

                }

               

            }

            System.out.println();

        }

       

    }

}

 

 

/*

 * WAP to get the following output:

        1   

        1    2   

        1    2    3   

        1    2    3    4   

        1    2    3    4    5   

 

 */

 

 class tri_num_invert

 

{

    public static void main()

    {

        int i,j;

        for (i=1;i<=5;i++)      //rows

        {

           

            for(j=1;j<=i;j++)   //column

            {

                System.out.print(j +"\t");

               

            

            }

            System.out.println();

        }

    }                                                                                                                       

}

 


Communication and Network

 


Chapter 2 Communication and network technologies


click here to open the file in pdf format

Q1.(a)Explain the term bit streaming.

– sequence of digital signals / bits

– over a communication path / Internet

– transfer of data at high speed

– requires fast broadband connection

– requires some form of buffering

– bits arrive in the same order as sent

(b) A person watches a film streamed from a website on a tablet computer.

(i) Give two benefits of using bit streaming for this purpose.

– no need to wait for a whole file to be downloaded

– no need to store large files on user’s computer

– allows on demand playback

– no specialist software is required for playback in browser

(ii) State two potential problems of using bit streaming for this purpose.

video stops / hangs if very slow Internet / broadband speed low

– video stops / hangs if inadequate buffering capacity

– loss of Internet means can’t access films / files

– may require specific software to run the files / films

– viruses can be downloaded from the websites

(c) Explain the terms on-demand bit streaming and real-time bit streaming.

on-demand:

– digital video tape, analogue video tape, or digital files are converted to bit streaming –

format for broadcasting on the net; this is known as encoding, these encoded streaming

video files are then uploaded to a dedicated server

– a link for the encoded video is placed on a web site

– a user clicks on the link to download the encoded streaming video; the streamed video is

– then broadcast to the user as and when they require it

– can be paused / can go back and re-watch / fast-forward, etc.

 

real-time:

– an event is captured live with a video camera

– the video camera is connected to a computer

– the video signal is converted to streaming media files (encoded) on the computer

– the encoded feed is then uploaded from the computer to a dedicated streaming server

via cable, DSL, or a high-speed internet connection

– the server then sends the live images it to all users requesting it as real-time video

streaming

– cannot be paused etc.

2 (a) The table shows four statements about IP addresses.

Tick () to show which of the statements are true.

 

 

 

(b) Consider the URL:

http://cie.org.uk/computerscience.html

 

(i) Give the meaning of the following parts of the URL.

http

cie.org.uk

computerscience.html

 

http –

enables browser to know what protocol is being used to access information in the domain

cie.org.uk –

cie.org.uk is the domain name

 

computerscience.html –

actual web page / file being viewed

 

(ii) Sometimes the URL contains the characters %20 and ?.

Describe the function of these characters.

 

%20 – because <space> not allowed in a URL, %20 is the coding for a space (32 in denary)

 

? – separates the URL from all parameters or variables

 

 

3 A company operates a chemical plant, which has a number of processes. Local computers monitor these processes and collect data.

The computers transfer these data to a central computer 50 km away. A telecommunications company (telco) provides cables.

Engineers at the telco had to decide which type of cable to use. They considered the use of either copper cable or fibre optic cable.

State two benefits of each type of cable. Each benefit must be clearly different.

 

Benefits of copper cable

 

Benefits of fibre optic cable

 

 

 

Benefits of fibre optic cable

 

fibre optic cables have greater bandwidth

– fibre optic cables need less signal boosting // can transmit over longer distances

– fibre optic cables have greater security (more difficult to “tap” into)

– fibre optic cables are immune to electromagnetic and other effects

– fibre optic cabling is lighter in weight (easier to install)

– fibre optic cables consume less power

 

Benefits of copper cable

 

– copper cabling is less expensive to install

– copper cable is easier to install because it is more flexible

– it is easier to make terminations using copper cabling

– the expertise in use of copper cabling is more extensive

– has been around for years … so very little is “unknown” about installations using this type

of cabling

 

 

 

 

4 (a) (i) Describe what is meant by a client-server model of networked computers.

(i) – at least one computer used to “serve” …

– … other computers are referred to as “clients”

– server provides services / applications etc. …

– … which may be requested by clients

 

 

 

 

 

 

 

 (ii) Give two benefits of using the client-server model.[2]

– files and resources are centralised

– creation of security / manage security

– user needs user name and password to access network

– centralised back-up

– intranet capability

– Internet monitoring

– clients can be less powerful machines, therefore less expensive to buy

– saving resources on server reduces the burden on the client.

 

 

Name the hardware device labelled X.

Router

 

 

 

 

 

(c) A web page offers a link for users to request another web page. The requested web page contains HTML code and JavaScript code.

Put each statement in the correct sequence by writing the numbers 1 to 5 in the right-hand column.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

5 (a) Telephone calls can be made by using:

• conventional telephones (using the Public Service Telephone Network (PSTN) system)

over a wired network

• a computer, equipped with speakers and microphone, connected to the Internet

Put a tick (ü) in the correct column to match each description to the appropriate communication

method.[5]

 

 

 

 

 

 

(b) Distinguish between the Internet and the World Wide Web (WWW).

Internet

massive network of networks/interconnected network of computer devices

Internet stands for Interconnected Networks

uses TCP/IP protocol

World Wide Web (www)

is a collection of (multimedia) web pages/documents

...stored on websites

http/protocols used to transmit data

web pages are written in HTML

URLs specify the location of the web pages

web documents are accessed using browsers

 

 

(c) Name the hardware device that is being described:

(i) A device that transfers data from one network to another in an intelligent way. It has the task of forwarding data packets to their destination by the most efficient route.

(ii) A device used between two dissimilar LANs. The device is required to convert data packets from one protocol to another.

(iii) A device or software that provides a specific function for computers using a network. The most common examples handle printing, file storage and the delivery of web pages.

(i)Router

(ii)gateway

(iii) server

 

 

 

 

 

 

 

6 Access to World Wide Web content uses IP addressing.

(a)                State what IP stands for.

 

 (b) The following table shows four possible IP addresses.

Indicate for each IP address whether it is valid or invalid and give a reason.

 

 

C)Describe two differences between public and private IP addresses.

 

 

A] Internet Protocol

 

B]

 

C]

Public address can be reached across the Internet.

Private address can only be reached internally/through the LAN/Intranet // private address cannot be reached across the Internet.

NAT (Network Address Translation) is necessary for a private IP address to access the Internet directly.

A private address is more secure than a public address // A public address is less secure than a private address.

Public addresses are provided by ISP / assigned by InterNIC // Private addresses are assigned by the router (of the network concerned).

Public addresses are unique (to the Internet) // Private addresses (are unique within their network, but) can be duplicated within other (discrete) networks.

10.0.0.1 to 10.255.255.254 and 172.16.0.1 to 172.31.255.254 and 192.168.0.1.to 192.168.255.254 form the private address space // IP addresses from the private address space are never assigned as public.

 

 

Q7)

The design of a web-based application can require the use of client-side scripting.

(a)                Describe what is meant by client-side scripting.

 

The user’s web browser is the client software

        The requested web page has program code / script embedded within it

This code is interpreted by the web browser

 

 

 

 

(b)               A user requests a web page by keying the Uniform Resource Locator (URL) into the address bar of their web browser.

The requested page contains a client-side script.

Describe the sequence of steps leading to the display of the web page on the computer

screen.[4]

 

The browser parses the URL to obtain the Domain Name 1

The browser software passes the Domain Name to the nearest Domain Name

Server (DNS)

The DNS stores a list of Domain Names and matching IP addresses

The DNS Name Resolver looks for the Domain Name in its database

If found the corresponding IP address is returned to the originator

If not found the request is forwarded to another higher level DNS

The original DNS adds the returned IP address to its cache

The original DNS returns the IP address to the originator

The browser uses the IP address to request the required web page from the web

server

The web server retrieves the page and delivers it to the originator

The browser software interprets the script and displays the web page

 

 

 

 

 

 

 

(c) A web page used for data capture consists of:

two text boxes for the entry of:a product code the number of items to be purchased.

a button which is clicked when the user wants to submit this order.

 

 

 

 

 

 

 

 

 

 

 

The developer has used three variables in the JavaScript code. State the identifiers used.

Ans)

Message1, Message2 ,X

 

(ii) The button has an event whose identifier is onMouseDown. When the submit button is

clicked, some code is executed.

State the line numbers that contain this code.

From line .............................. to line ..............................

Ans)

6 – 19

 

(iii) The JavaScript code uses a selection statement.

State the line number that contains the condition.

Line number: .................................................................

Ans)

11

 

(iv) Describe the purpose of the validation check that the code performs.

 

Ans)Checks that the product code has not be left blank // presence check on product

code

 

 

 

 

 

 

(v) Name and describe two other types of validation check that could be appropriate for this

data capture form.

Validation check:

Description

Validation check:

Description

 

Ans)

Range check

Check the number entered is (say) between 1 and 100

Format check

Checks the product code is a particular format // Checks the number has digit

characters only // by example

Length check

The number of items has exactly five characters

Existence check

To ensure the product code has been assigned