Thursday, May 31, 2012

Creating a bus Image In PHP using Graphics


<?
$img=imagecreatetruecolor(600,600);
$grey=imagecolorallocate($img,200,191,191);
$brown=imagecolorallocate($img,152,50,50);

imagerectangle($img,245,155,516,253,$grey); //bus
imagerectangle($img,442,96,511,154,$grey); //top-square

imageline($img,244,172,516,172,$grey);
imageline($img,244,232,516,232,$white);

imagefilledrectangle($img,280,180,302,197,$grey); //window1
imagefilledrectangle($img,354,180,376,196,$grey); //window2
imagefilledrectangle($img,424,180,446,196,$grey); //window3

imagefilledellipse($img,295,275,50,50,$brown); //wheel left-outer
imagefilledellipse($img,295,275,20,17,$grey); //wheel left-inner
imagefilledellipse($img,440,280,50,50,$brown); //wheel right-outer
imagefilledellipse($img,440,280,20,17,$grey); //wheel right-inner

header('Content-Type:image/png');
imagePNG($img);
imagepng($img,"t4.png");
imagedestroy($img);
?>

Creating a circle image in PHP using Graphics


<?php 

// create a 200*200 image 
$img = imagecreate(200, 200); 
  
// allocate some colors 
$white = imagecolorallocate($img, 255, 255, 255); 
  
// draw a white circle 
imagearc($img, 100, 100, 150, 150, 0, 360, $white); 

// output image in the browser 
header("Content-type: image/png"); 
imagepng($img); 
  
// free memory 
imagedestroy($img); 

?>

Saturday, May 26, 2012

Creating a Table and Inserting values in table (JAVA)




import java.sql.*;
import java.io.*;
class CreateTable
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:coll");
                                   Statement stmt=conn.createStatement();
      stmt.executeUpdate("create table student1(rno INTEGER primary key,name VARCHAR,per FLOAT)");
System.out.println("Table created");

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the roll number");
int r = Integer.parseInt(br.readLine());
System.out.println("Enter name");
String name = br.readLine();
System.out.println("Enter per ");
double per=Double.parseDouble(br.readLine());
stmt.executeUpdate("insert into student1 values("+r+",' "+name+" ',"+per+")");
System.out.println("Record Inserted..");
stmt.close();
conn.close();
}
catch(Exception e){System.out.println(e.toString());}
}
}


Thursday, May 24, 2012

To Count the Number of Vowels (PHP)


<?php

$s=$_POST['str'];

$cnt=0;

for($i=0;$i<strlen($s);$i++)
{

if($s[$i]=="a" || $s[$i]=="e" || $s[$i]=="i" || $s[$i]=="o" || $s[$i]=="u")
{
echo "<br>".$s[$i];
$cnt++;
}

}
"<br>"."No of vowels :  ";
echo $cnt;


/*
echo $_POST['nm'];
$class = $_POST['class'];

echo $class;
*/
?>


Wednesday, May 23, 2012

Factorial (JAVA)


class Factorial
{
public static void main(String arg[])
{
if (arg.length!=1)
System.out.print("Invalid");
else
{
int n=Integer.parseInt(arg[0]);
int fact=1;
while(n>0)
{
fact=fact * n;
n--;
}
System.out.print("Factorial="+fact);
}
}
}