Slip No 2

Q.1 Write a JSP program to check whether given number is Perfect or not. (Use Include directive).

A) Write a JSP program to check whether given number is Perfect or not. (Use Include

directive).

Answer :

 Slip2A.html

<html>

<body>

    <h1>Find Perfect Number</h1>

    <form action=”http://127.0.0.1:8080/java/Slip2A.jsp” method=”GET”>

        Enter Number : <input type=’text’ name=’no’>

        <input type=’submit’ value=’SUBMIT’>

    </form>

</body>

</html>

Slip2A.jsp

<%@ page language=”java” %>

<html>

    <body>

        <%

            int n = Integer.parseInt(request.getParameter(“no”));

            int n1=0;

            for(int i=1; i<n; i++){

                if(n%i==0){

                    n1+=i;

                }

            }

            if(n1==n){

                out.println(“Perfect Number”);

            }else{

                out.println(“not Perfect Number”);

            }

        %>

    </body>

</html>

Q.2 Write a java program in multithreading using applet for drawing flag.

import java.awt.*;

public class Slip2B extends Frame{

    int f = 0;

    public Slip2B(){

        Signal s = new Signal();

        s.start();

        setSize(500,500);

        setVisible(true);

    }

    public void paint (Graphics g){

        switch (f){

            case 0 :

            g.drawLine(150, 50, 150, 300);

            case 1 :

            g.drawRect(150, 50, 100, 90);

        }

    }

class Signal extends Thread{

    public void run(){

        while(true){

            f = (f+1)%2;

            repaint();

            try{

                Thread.sleep(1000);

            }catch(Exception e){

            }

        }

    }

}

    public static void main(String args[]){

        new Slip2B();

    }

}

Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top