Showing posts with label Java Programs. Show all posts
Showing posts with label Java Programs. Show all posts

Tuesday, 21 August 2012

import java.io.*;
class f
{
int i,l,top=-1;
String s;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void read()throws IOException
{
System.out.print("Enter the string");
s=br.readLine();
}
public void postfix()throws IOException
{
int l=s.length();
for(i=0;i<l;i++)
{
char d=s.charAt(i);
if(d>=0 && d<=9)
{
push(d);
}
else
{char c1=pop();
char c2=pop();
switch (d)
{
case '+':push(c1+c2);break;
case '-':push(c1-c2);break;
case '*':push(c1*c2);break;
case '/':push(c1/c2);break;
//case '':push(c1%c2);break;
}
}
}}
public void push(int e)
{
if (top>=(l-1))
System.out.print("Stack is full");
else
{
top++;
s[top]=e;
}}
char pop()
{
char tp;
tp=s[top];
top--;
return(tp);

}
}
class InFixPost
{
public static void main (String args[])throws IOException
{
f t=new f();
t.read();
t.postfix();
}
}





import java.io.*;
class Subp
{
int a[],n,b[],j,i;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void getData()throws IOException
{
System.out.println("enter the limit and enter the nos:");
n=Integer.parseInt(br.readLine());
a=new int[n+1];
for( i=0;i<n;i++)
{
a[i]=Integer.parseInt(br.readLine());
}}
public void display()
{
System.out.print("reverse is ");
b=new int[21];
for(i=0,j=n-1;i<n;i++,j--)
{
b[j]=a[i];
}
for(i=0,j=n;i<n;i++,j--)
{
a[i]=b[i];
System.out.print(a[i]);
}
}
}
class Array
{
public static void main(String arg[])throws IOException

{
Subp t=new Subp();
t.getData();
t.display();
}
}
class arm
{
public static void main(String arg[])
{
int n,t,s,r;
n=Integer.parseInt(arg[0]);
t=n;
s=0;
while(n>0)
{
r=n%10;
s=s+(r*r*r);
n=n/10;
}
if(t==s)
{
System.out.println("Given no. "+t+" is an armstron");
}
else
{
System.out.println("Given no. "+t+" is not anarmstron");
}
}
}

Friday, 8 June 2012


 
import java.io.*;
class Link
{
int data;
Link next;
Link last;
public Link(int item)
{
data =item;
}
public void displayNode()
{
System.out.println("data is"+data);
}
}
class LinkList
{
Link first;
import java.io.*;
class DeSub{
int q[];
int size,r=-1,f=0;
public DeSub(int s)
{
size = s;
q=new int[s];
}
public void insert_first(int val)
{
if (r-f==size-1)
System.out.println("queue full");
else if (r==-1)
{
q[++r]=val;
}
 
import java.io.*;
class Queue
{
int s,f=0,a[],i,r=-1,count=0;
Queue(int x)
{
s=x;
a=new int [s];
}
public void input(int e)
{
if(count==s)// count controls the whole Q
{System.out.print("it is full...");
}
count++;
if (r==(s-1))
{
r=0;
a[r]=e;
}
else
{
r++;
a[r]=e;
}}
public void bot()
{if(count==0)
{System.out.print("Q is empty ...");
}

Java Program for Implemet Merge Sort

Posted by Unknown On 11:32 | No comments

import java.io.*;
class merge
{
static DataInputStream d = new DataInputStream(System.in);
int a[],n;
public void insert()throws IOException
{
System.out.println("Enter array size : ");
n=Integer.parseInt(d.readLine());
a=new int[n];
System.out.println("Enter the elements");
for(int i=0;i<n;++i)
a[i]=Integer.parseInt(d.readLine());
}
 
import java.io.*;
class Sub
{
int a[],n,b[],j,i;
   
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void getData()throws IOException
{
System.out.println("enter the limit and enter the nos:");
n=Integer.parseInt(br.readLine());
a=new int[n+1];
for( i=0;i<n;i++)
{
a[i]=Integer.parseInt(br.readLine());
}}
 
class Subp
{
int a[],n,b[],j,i,t,p;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void getData()throws IOException
{
System.out.println("enter the limit and enter the nos:");
n=Integer.parseInt(br.readLine());
a=new int[n];
for( i=0;i<n;i++)
{
a[i]=Integer.parseInt(br.readLine());
}}

Blogroll

Blogger templates

About