ns28
Q1]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
String input = request.getParameter("input");
if (input != null && !input.isEmpty()) {
String reversed = new StringBuilder(input).reverse().toString();
%>
<p>Original String: <%= input %></p>
<p>Reversed String: <%= reversed %></p>
<%
}
%>
</body>
</html>
Q2]
public class CurrentThreadName {
public static void main(String[] args) {
Thread thread1 = new Thread(new MyRunnable(), "Thread 1");
Thread thread2 = new Thread(new MyRunnable(), "Thread 2");
Thread thread3 = new Thread(new MyRunnable(), "Thread 3");
thread1.start();
thread2.start();
thread3.start();
}
static class MyRunnable implements Runnable {
@Override
public void run() {
String threadName = Thread.currentThread().getName();
System.out.println("Currently executing thread: " + threadName);
}
}
}