Posts

Showing posts from September, 2012

Java Script Example for WHILE Loop

<html > <head> <title>JavaScript While Loop</title> <script type="text/javascript"> var myarray=new Array(5); myarray[0]="Sonam"; myarray[1]="Jamtsho"; myarray[2]="Karma"; myarray[3]="Phuntsho"; myarray[4]="Tshering"; var name=prompt("Enter a name to search:"); var i=0; while(i<myarray.length)   {    if(name==myarray[i])      {       document.write(name+ " is located at position "+(i+1));       break;      }     i++;   } </script> </head> <body> </body> </html>

Java Script Example for FOR..IN loop for finding String Length

<html > <head> <title>Java Script Example for FOR..IN LOOP</title> <script type="text/javascript"> var str="Sonam Jamtsho"; var i; var len=0; for(i in str)  {   len++;  }  document.write("The length of the string is: "+len); </script> </head> <body></body> </html>

Java Script, For loop Example, Array

<html> <head> <title>JavaScript Example for  For Loop</title> <script type="text/javascript"> var myarray=new Array(5); myarray[0]="Sonam"; myarray[1]="Jamtsho"; myarray[2]="Karma"; myarray[3]="Phuntsho"; myarray[4]="Tshering"; var i; for(i=0;i<myarray.length;i++)   {    document.write("array["+i+"]= "+myarray[i]);    document.write("</br>");   } </script> </head> <body></body> </html>

Java Programming- Example of Abstract Class and Abstarct Method

Image
//Abstract Class is a class which contains atleast one abstract method. Abstract class cannnot be instantiated i.e. object cannot be created for that class. The methods are implemented in the subclass or base class. import java.io.*; abstract class Shape //Abstract Class    {     abstract void draw(); //Abstract Method    } class Rectangle extends Shape{ void draw()   {     System.out.println("Draw Rectangle Here");   } } class Traingle extends Shape    {     void draw()       {         System.out.println("Draw Traingle Here");       } } class AbstractClass Example    {     public static void main(String args[])       {        //Shape s=new Shape();//This ia Illegal Now       Shape ob1=new Rectangle(); ...