Archive for February, 2012

 

import java.io.*;
class showfile
{
public static void main(String arg[]) throws IOException
{
int i;
InputStream fis=new FileInputStream(arg[0]);

while(true)
{
i=fis.read();
if(i==-1)
break;
else
System.out.print((char)i);
}
fis.close();
}
}

NOTE: COMPILE THE PROGRAM FIRST FOLLOWED BY THE COMMAND:

java <classname> <filename.filetype>

               eg: java showfile mytext.txt

Advertisements

WHAT IS IT ? : It is an collection of elements in which the elements can be inserted or deleted only at one known as top of stack. So it is similar to a pipe with one open end. The element inserted first will be removed last hence the concept of ‘LAST IN FIRST OUT’ and hence called LIFO structure.

Simple Java program to demonstrate working of stack.

import java.util.*;
class stack
{
static int a[]=new int[5];
static int top=0;
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
while(true)
{
System.out.println(” 1:PUSH \n 2:POP \n 3:DISPLAY \n 4:EXIT!”);
int n=sc.nextInt();
switch(n)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
System.exit(0);
break;
default:
System.out.println(“INVALID ENTRY”);
break;
}
}
}
static void push()
{
top++;
if(top>5)
{
System.out.println(“OVERFLOW!”);
}
else
{
System.out.println(“ENTER AN ELEMENT TO BE PUSHED ? “);
Scanner sc=new Scanner(System.in);
int b=sc.nextInt();
a[top]=b;
}
}
static void pop()
{
if (top==-1)
{
System.out.println(“Stack is underflowing !!!”);
}
else
{
int x=a[top];
top–;
System.out.println(“ELEMENT HAS BEEN POPPED : “+x);
}
}
static void display()
{
System.out.println(“Stack elements are :”);
for(int i=top;i>0;i–)
{
System.out.println(a[i]);
}
}
}

PL-SQL (Runtime value)

Posted: February 8, 2012 in PL-SQL

Run time value

Whenever this program(query) is executed the viewer asks the user to enter a value (consider ’56’ ) it displays the result as below.

This is a basic program to accept inputs from user and display the same on the screen.

1)
declare
i int;
begin
i:=&i;
DBMS_OUTPUT.PUT_LINE(i);
end;

o/p:
enter value for i: 56

$
$$
$$$
$$$$
$$$$$
$$$$$$
$$$$$$$
$$$$$$$$
$$$$$$$$$
$$$$$$$$$$
$$$$$$$$$$$
$$$$$$$$$$$$
$$$$$$$$$$$$$
$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$
@@@@@@@@@@@@@@
@@@@@@@@@@@@@
@@@@@@@@@@@@
@@@@@@@@@@@
@@@@@@@@@@
@@@@@@@@@
@@@@@@@@
@@@@@@@
@@@@@@
@@@@@
@@@@
@@@
@@
@


import java.util.*;
class Demo1
{
public static void main(String g[])
{

for (int i=1; i<=15; i++)
{
System.out.println();
for (int j=1; j<=i; j++)
{
System.out.print(“$”);
}
}
System.out.println();

for(int m=1;m<15;m++)
{
for(int n=m;n<15;n++)
{
System.out.print(“@”);
}
System.out.println();
}

}
}

Just getting used to this blog !

Posted: February 7, 2012 in Java Programs

Okay this is my first post here, so I will start writing about some basic programs in the upcoming posts ..keep in touch ..I’ll soon update it !