Pattern Problem | Rectangle Pattern


Test Case #1

Enter length:
10
Enter breadth:
4

Output

**********
*               *
*               *
**********

Test Case #2

Enter length:
50
Enter breadth:
10

Output

**************************************************
*                                                                                         *
*                                                                                         *
*                                                                                         *
*                                                                                         *
*                                                                                         *
*                                                                                         *
*                                                                                         *
*                                                                                         *
**************************************************

Program

import java.util.*;

package jothibasu.com;

public class RectanglePattern {

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int length,breadth;
System.out.println("Enter length:");
length = scan.nextInt();
System.out.println("Enter breadth:");
breadth = scan.nextInt();
//First Line
for (int i = 0 ; i < length ; i++)
System.out.print("*");
//Moving to next line
System.out.println();
/*Execute the loop up to breadth
  Here [breadth-2] given because
  of considering 1st and last line*/
for (int j = 0 ; j < breadth - 2 ; j++) {
//First * of breadth
System.out.print("*");
//Printing the space inside rectangle
for (int k = 0 ; k < length - 2 ; k++)
System.out.print(" ");
//Last * of breadth
System.out.print("*");
//Moving to next line
System.out.println();
}
//Last line
for (int l = 0 ; l < length ; l++)
System.out.print("*");
//Closing the scanner object
scan.close();
}
}

Pattern Problem | Alphabets

Test Case #1

Enter limit:
Z
Enter difference:
1

Output 

A
C
E
G
I
K
M
O
Q
S
U
W
Y

Test Case #2

Enter limit:
Z
Enter difference:
2

Output

AD
GJ
MP
SV
Y

Test Case #3

Enter limit:
Z
Enter difference:
3

Output

AEI
MQU
Y

Program


import java.util.*;

package jothibasu.com;

public class Pattern {

   public static void main(String[] args) {
int counter = 1;
char limit;
int difference;
Scanner scan = new Scanner(System.in);
System.out.println("Enter limit:");
limit = scan.next().charAt(0);
System.out.println("Enter difference:");
difference = scan.nextInt();
//Loop will execute up to the given limit
for (char value = 'A'; value <= limit ; value++) {
System.out.print(value);
//Converting character into integer 
                  [Type Conversion, ASCII value]
int charToInteger = (int) value;
//Add the difference to that integer value
charToInteger = charToInteger + difference;
//Converting integer to character
value = (char) charToInteger;
//Move to new line based on the difference given
if (counter % difference == 0)
System.out.println("");
counter++;
//Closing the scanner class object
scan.close();
}
}
}


Internet Programming | Http is a Stateless

Http is a Stateless


Because a stateless protocol does not require the server to retain session information or status about each communications partner for the duration of multiple requests. 
HTTP is a stateless protocol, which means that the connection between the browser and the server is lost once the transaction ends.

Java Servlet code for print out the current date and time

Java Servlet code for print out the current date and time



import java.io.PrintWriter;
import java.io.IOException;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
   This servlet prints out the current date and time.
*/
public class DateServlet extends HttpServlet
{
   public void doGet(HttpServletRequest request,
      HttpServletResponse response)
      throws ServletException, IOException
   {
      // get information
      String now = new Date().toString();

      // set content type to HTML
      response.setContentType("text/html");

      // print formatted information
      PrintWriter out = response.getWriter();

      String title = "Date Servlet";
      out.println("<html><head><title>");
      out.println(title);
      out.println("</title></head><body><h1>");
      out.print(title);
      out.println("</h1><p>The current time is: ");
      out.println(now);
      out.println("</p></body></html>");

      out.close();
   }
}

JavaScript HTML DOM Elements (Nodes) | Removing Existing HTML Elements

Removing Existing HTML Elements

To remove an HTML element, you must know the parent of the element:

Example


<!DOCTYPE html>
<html>
<body>

<div id="div1">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>

<script>
var parent = document.getElementById("div1");
var child = document.getElementById("p2");
parent.removeChild(child);
</script>

</body>
</html>

Output

This is a paragraph.


The method node.remove() is implemented in the DOM 4 specification.
But because of poor browser support, you should not use it.

Example Explained 

This HTML document contains a <div> element with two child nodes (two <p> elements):
<div id="div1">
<p id="p1">This is a paragraph.</p>
<p id="p2">This is another paragraph.</p>
</div>
Find the element with id="div1":
var parent = document.getElementById("div1");
Find the <p> element with id="p1":
var child = document.getElementById("p1");
Remove the child from the parent:
parent.removeChild(child);
It would be nice to be able to remove an element without referring to the parent.
But sorry. The DOM needs to know both the element you want to remove, and its parent.
Here is a common workaround: Find the child you want to remove, and use its parentNode property to find the parent:
var child = document.getElementById("p1");
child.parentNode.removeChild(child);