Thursday, September 6, 2012

clear screen in java

Clearing the screen with Java in platform independent way (on both Windows and Linux platform).
Here are the videos that show how to clear the console:

Part 1


Part 2


You can download JANSI from http://jansi.fusesource.org/
You can refer to the API docs from http://jansi.fusesource.org/documentation/api/index.html

Monday, September 3, 2012

one program many ways

Program to check whether a number is positive, negative or is zero: (I did this while one of the teaching sessions in a few minutes to encourage student for coming out with new solutions )many programs same thing:

  1:
#include<stdio.h>

int main()
{
 int a,b;
 
 printf("enter the number");
 scanf("%d",&a);
 if(a==0)
 {
  printf(" %d number is 0",a);
 }
 else 
 {
  if(a>0)
  {
   printf(" %d number is possitive",a); 
  }
  else
  {
   printf("%d number is nagitive",a);
  }
 }
 
 return 0;
}



  2:

#include<stdio.h>

int main()
{
 int a,b;
 
 printf("enter the number");
 scanf("%d",&a);
 if(a>0)
 {
  printf(" %d number is possitive",a); 
 }
 else if(a<0)
 {
  printf("%d number is nagitive",a);
 } 
 else if(a==0)
 {
  printf(" %d number is 0",a);
 }
 
 
 return 0;
}
  3:

#include<stdio.h>

int main()
{
 int a,b;
 
 printf("enter the number");
 scanf("%d",&a);
 if(a>0)
 {
  printf(" %d number is possitive",a); 
 }
 else if(a<0)
 {
  printf("%d number is nagitive",a);
 } 
 else
 {
  printf(" %d number is 0",a);
 }
 
 
 return 0;
}
  4:

#include<stdio.h>

int main()
{
 int a,b;
 
 printf("enter the number");
 scanf("%d",&a);
 if(a>0 || a<0 )
 {
  if(a>0)
  {
   printf(" %d number is possitive",a);   
  }
  else if(a<0)
  {
   printf("%d number is nagitive",a);
  }
 } 
 else
 {
  printf(" %d number is 0",a);
 }
 
 
 return 0;
}
  5:

#include<stdio.h>

int main()
{
 int a,b;
 
 printf("enter the number");
 scanf("%d",&a);
 if(a>0 | a<0 )
 {
  if(a>0)
  {
   printf(" %d number is possitive",a);   
  }
  else if(a<0)
  {
   printf("%d number is nagitive",a);
  }
 } 
 else
 {
  printf(" %d number is 0",a);
 }
 
 
 return 0;
}
  6:
#include<stdio.h>

int main()
{
 int a,b;
 
 printf("enter the number");
 scanf("%d",&a);
 if(a!=0)
 {
  if(a>0)
  {
   printf(" %d number is possitive",a); 
  }
  else
  {
   printf("%d number is nagitive",a);
  }
  
 }
 else 
 {
  printf(" %d number is 0",a); 
 }
 
 return 0;
}