Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 30 Answers


A) Write a JSP script to accept a String from a user and display it in reverse order.

Answer :

<%@ page language="java" %>
<html>
<head>
  <title>Reverse String Example</title>
</head>
<body>
  <h1>Reverse String Example</h1>

  <form method="post">
    Enter a String: <input type="text" name="inputString"><br><br>
    <input type="submit" value="Reverse">
  </form>

  <br><br>

  <%
    String inputString = request.getParameter("inputString");
    if (inputString != null && !inputString.isEmpty()) {
      String reversedString = new StringBuilder(inputString).reverse().toString();
      out.println("Original String: " + inputString + "<br>");
      out.println("Reversed String: " + reversedString);
    }
  %>

</body>
</html>

Output :

 

B) Write a java program in multithreading using applet for moving car.

Answer :

import java.applet.Applet;

import java.awt.*;

 

public class Slip30B extends Applet implements Runnable {

    int x, z;

    Thread t;

    Image pic;

 

    public void init() {

        x = 50;

        pic = getImage(getDocumentBase(), "./car.png");

        t = new Thread(this);

        t.start();

    }

 

    public void run() {

 

        while (true) {

            repaint();

            x = x + 10;

            if (x >= this.getWidth()) {

                System.exit(0);

            }

            try {

                Thread.sleep(100);

            } catch (Exception e) {

            }

        }

    }

 

    public void paint(Graphics g) {

        g.drawLine(0, 165, this.getWidth(), 165);

        g.drawImage(pic, x, 120, this);

    }

}

 

/*

 * <applet code="Slip30B.java" width="800" height="500">

 * </applet>

 */


Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 30 Answers Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 30 Answers Reviewed by technical_saurabh on December 15, 2022 Rating: 5

No comments:

Powered by Blogger.