Q.1.
Advanced Java:
A)
Write a JSP program to accept Name and Age of Voter and check whether he is
eligible
for voting or not.
Answer :
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Voter Eligibility Checker</title>
</head>
<body>
<h1>Voter Eligibility Checker</h1>
<form method="post" action="check_voter.jsp">
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br>
<label for="age">Age:</label>
<input type="number" id="age" name="age"><br>
<input type="submit" value="Check Eligibility">
</form>
<%
String name = request.getParameter("name");
int age = Integer.parseInt(request.getParameter("age"));
if(age >= 18) {
out.println("<p>"+ name +", you are eligible to vote.</p>");
} else {
out.println("<p>"+ name +", you are not eligible to vote yet.</p>");
}
%>
</body>
</html>
Output :
B)
Write a Java program to display given extension files from a specific directory
on
server machine.
Answer :
import java.io.File;
import java.util.Scanner;
public class DisplayFilesWithExtension {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the directory path: ");
String directoryPath = scanner.nextLine();
System.out.print("Enter the file extension (without dot): ");
String fileExtension = scanner.nextLine();
File directory = new File(directoryPath);
File[] files = directory.listFiles((dir, name) -> name.endsWith("." + fileExtension));
if (files.length == 0) {
System.out.println("No files found with the given extension in the directory.");
} else {
System.out.println("Files with ." + fileExtension + " extension in the directory:");
for (File file : files) {
System.out.println(file.getName());
}
}
}
}
Output :
Savitribai Phule Pune University T.Y.B.B.A.(C.A.) Advanced Java Practical Slip 14 Answers
Reviewed by technical_saurabh
on
September 21, 2022
Rating:

No comments:
Post a Comment