OneCompiler

j8

198

/*

  1. Write a java program to define a thread for printing text on output screen for ‘n’
    number of times. Create 3 threads and run them. Pass the text ‘n’ parameters to the
    thread constructor.
    Example:
    i. First thread prints “COVID19” 10 times.
    ii. Second thread prints “LOCKDOWN2020” 20 times
    iii. Third thread prints “VACCINATED2021” 30 times
    */
    package com.mycompany.practical_slip;

class T1 extends Thread {
String msg;

T1(String msg) {
    this.msg = msg;
}

public void run() {
    for(int i=0; i<10; i++)    
        System.out.println(msg);
}

}

class T2 extends Thread {
String msg;

T2(String msg) {
    this.msg = msg;
}

public void run() {
    for(int i=0; i<20; i++)
        System.out.println(msg);
}

}
class T3 extends Thread {
String msg;

T3(String msg) {
    this.msg = msg;
}

public void run() {
    for(int i=0; i<30; i++)
        System.out.println(msg);
}

}

public class slip8_1
{
public static void main(String[] args) {
T1 t1 = new T1("COVID19");
T2 t2 = new T2("LOCKDOWN2020");
T3 t3 = new T3("VACCINATED2021");

    t1.start();
    t2.start();
    t3.start();
}

}

2).jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> <style> .prime { color: red; } </style> </head> <body> <h1>Is prime?</h1> <form action="S8Q2.jsp" method="post"> Enter a number: <input type="text" name="num"> <input type="submit" value="is prime ?"> </form> <% String numStr = request.getParameter("num"); int n = 0;
        if(numStr != null && !numStr.isEmpty()) {
            n = Integer.parseInt(numStr);
            
            if(n > 1) {
                boolean isPrime = true;
                for(int i=2; i<n; i++) {
                    if(n % i == 0) {
                        isPrime = false;
                        break;
                    }
                }
                
                if(isPrime) {
    %>
                    <h3 class="prime">Prime number</h3>
    <%
                } else {
    %>
                    <h3 class="prime">Not a prime number</h3>
    <%
                }
            }
        }
    %>
</body>
</html>