Search This Blog

Thursday, 24 January 2019

2. Write a Java program to create a vector, add elements at the end, at specified location onto the vector and display the elements. Write an option driven program using switch…case.


import java.util.*;
import java.io.*;
import java.lang.String;

class VectorPro
{
    public static void main(String args[])
    {
        try
        {
       
            int length = args.length;
            int i,ch;
            String str1,str2;

            Vector list = new Vector();

            for( i=0;i<length;i++)
            {
                list.addElement(args[i]);
            }

            DataInputStream in= new DataInputStream(System.in);
           
            for(;;)
            {
                System.out.println("1.Add element at end");
                System.out.println("2.Add element at specific location");
                System.out.println("3.Display");
                System.out.println("4.Exit");       
                System.out.println("Enter your choice:");
   
                str1=in.readLine();
                ch=Integer.parseInt(str1);

                switch(ch)
                {
                   
             case 1: System.out.print("Enter an element to insert at end:");
                            str2=in.readLine();
                            list.addElement(str2);
                            length++;   
                            break;
                       
             case 2: System.out.print("Enter an element & position:");
                            str1=in.readLine();
                            str2=in.readLine();
                            int pos;
                            pos=Integer.parseInt(str2);
                            if(pos<=length && pos>0)
                            {
                                list.insertElementAt(str1,pos-1);
                                length++;
                                break;
                            }
                            else
                            {
                                System.out.println("Invalid Position!");
                            }
                   
            case 3:
                            System.out.println("List of elements:");
                            for(i=0;i<length;i++)
                            System.out.println(list.elementAt(i));
                            break;
                   
            default:       System.exit(0);
   
                }
                              
            }
        }
        catch(Exception e){}
    }
}

1. Java program to generate first odd numbers then pick and display prime numbers among them.



import java.io.*;

public class OddNumber

{

     public static void main(String args[]) throws IOException

     {

           int limit;

           int b=0;

           limit = Integer.parseInt(args[0]);

           int a[]= new int[50];

           System.out.println("Odd numbers between 1 and " + limit);

           for(int i=1; i <= limit; i++)

           {

                boolean isPrime = true;

                           for(int j=2; j < i ; j++)

                           {                       

                                 if(i % j == 0)

                                 {

                                      isPrime = false;

                                      break;

                                 }

                           }

                //if the number is not divisible by 2 then it is odd

                           if( i % 2 != 0)

                           {

                           System.out.print(i + " ");

                           }

                           if(isPrime)

                           {

                                 if(i>2)   //1 is not prime and 2 is even.

                                 {

                                      a[b] =i;

                                      b++;

                                 }

                           }

           }

           System.out.println("\nPrime numbers are as follows:");

                for(int k=0;k<=b-1;k++)

                           System.out.println(a[k]);

     }

}

Thursday, 30 August 2018

2. Write a program to upload and display an image using PHP.
 <HTML>
<HEAD>
<TITLE>PHP PROGRAM TO UPLOAD A FILE.</TITLE>
</HEAD>
<BODY>

<FORM ACTION="fileupload.php" ENCTYPE="MULTIPART/FORM-DATA" METHOD="POST">
<b>Select the Image to upload:</b>
<INPUT TYPE="file" NAME="file"><BR/>
<INPUT TYPE="Submit" VALUE="Upload" NAME="Upload"> <BR/>
</FORM>

<?php
if(isset($_POST['Upload']))
{
    $path = "photos/" . $_FILES["file"]["name"];

    if(move_uploaded_file($_FILES["file"]["tmp_name"], $path))
    {
        echo "<img src=",$path," height=250 width=500 >";
    }
    else
    {
        echo "Error!";
    }
}
?>

</BODY>
</HTML>

1. Write a program to connect the mysql-database and display connection status using PHP.

1. Write a program to connect the mysql-database and display connection status using PHP.
<HTML>
<HEAD>
<TITLE> MYSQL Connection Status</TITLE>
</HEAD>
<BODY BGCOLOR="BEIGE" SIZE=22 TEXT=BLUE>
<?php
$servername = "localhost";
$username = "man";
$password = "";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error)
{
    die("Connection failed: " . $conn->connect_error);
}
echo "MySQL Connected successfully.";
?>
</BODY>
</HTML>

Wednesday, 15 August 2018

6. Create a webpage to demonstrate the use of external Cascading Style Sheets

6. Create a webpage to demonstrate the use of external Cascading Style Sheets
Code for mystyle.css:
body{
        background-color: orange;
        font-family:serif;
        color: blue;
        font-size: 26pt;
    }

h3{ color:blue; }

.M { color: Magenta; font-style:italic  }
.Y { color:yellow; font-style:bold }
.R { color:Red; text-decoration:underline }

ul {
     list-style-type: square;
   }


Code for External.html:
<HTML>
    <HEAD>
        <TITLE>External CSS</TITLE>
        <LINK  REL="stylesheet" HREF="mystyle.css">
    </HEAD>
    <BODY>
        <H3>Applying Styles using External Cascading Style Sheets</H3>
       
        <span class="M">This text is Italic and Magenta.</span><br>
        <span class="Y">This text is Bold and Yellow.</span><br>
        <span class="R">This text is underlined and Red.</span><br>
       <P>This list is applied with External CSS:</P>
       <ul>
       <li>Element1
       <li>Element2
       </ul>
   
    </BODY>
</HTML>
FREE Hit Counters