Posts

Showing posts from August 21, 2011

nibble and its reverse

//nibble and decimal number  reverse  a simple illustrations through program. itprofessionalsrocks.blogspot.com #include<iostream.h> #include<conio.h> void main() {   int a,p,d,t,i=1,nib=0,rev=0;   cout<<"enter the decimal number" ;   cin>>a;   p=a;   while(a>0)   {    t=a%4;    nib=nib+t*i;    i=i*10;    a=a/4;   }   cout<<nib;   while(p>0)   { d=p%10;   rev=rev*10+d;   p=p/10;   }      cout<<"number after reversing"<<rev;   getch(); } itprofessionalsrocks.BLOGSPOT.COM

dec 2 hex 2 oct 2 bin

itprofessionalsrocks.blogspot.com //decimal to hexadecimal conversion,octal conversion,binary conversion //dec 2 hex 2 oct 2 bin CONVERSION// #include<iostream.h> #include<conio.h> void main() { clrscr(); int a,d,t,p,k=1,i=1,j=1; int bin=0,bin1=0,bin2=0,bin3=0,rev=0; cout<<"enter the number"; cin>>a; cout<<"enter the number for its conversion to binary"; cin>>t; p=a; while(a>0) { d=a%8; bin=bin+i*d; a=a/8; i=i*10; } while(t>0) { d=t%2; bin1=bin1+j*d; t=t/2; j=j*10; } while(p>0) { d=p%16; bin2=bin2+k*d; p=p/16; k=k*10; } cout<<"binary\n"<<bin1; cout<<"octal\n" <<bin; cout<<"hexadecimal\n"<<bin2; getch(); }

prime in java

to calculate whether the number is prime or not.prime in java javalearing.blogspot.com itprofessionalsrocks.blogspot.com class prime { public static void main(String args[]) { int num=11; int i; for( i=2;i<num;i++) { int n=num%i; if(n==0) { System.out.println("not prime"); break; } } if(i==num){ System.out.println("prime number"); }  }   }

package implementation in java

itprofessionalsrocks.blogspot.com Here we will show u a simple program of packages and its implementation. first create a package naming pack(any name)then create class and its method should be static and public  as shown  below: package pack; public class hemant { public static void show(String s) {     System.out.println(s);     }     } save above as hemant.java now compile your file as: javac hemant.java now make another file in which you wanted to import your package for example demo.java import pack.hemant; //for importing package pack having class name hemant class demo { public static void main(String args[]) { hemant.show("hi bye"); } } save above as demo.java compile your package class first:        javac hemant.java compile your another file create by you: javac demo.java run your demo file:java demo output: hi bye finally you get the clear concept of packages.

JAVA PROGRAM ON OBJECTS AND ITS CLASS

itprofessionalsrocks.blogspot.com HERE WE HAVE BOX AS A CLASS WITH WIDTH,HEIGHT AND DEPTH AS ATTRIBUTES AND VOLUME AS METHOD.PROGRAM IS SELF EXPLAINATORY. class box { double width; double height; double depth; public void volume() { System.out.println("volume is "); System.out.println(width*height*depth); } } class boxdemo { public static void main(String args[]){ box mybox1=new box(); box mybox2=new box(); mybox1.width=100; mybox1.height=20; mybox1.depth=10; mybox2.width=3; mybox2.height=6; mybox2.depth=7; mybox1.volume(); mybox2.volume(); } }

NOTEPAD OPENING USING JAVA

itprofessionalsrocks.blogspot.com QUESTION:NOTEPAD OPENING USING JAVA: Here we use ProcessBuilder class and create its object following is a simple program opening notepad using java. import java.io.*; import java.util.*; class notepad { public static void main(String args[]) { try { ProcessBuilder proc=new ProcessBuilder("notepad.exe","report"); proc.start(); } catch (Exception e) { System.out.println("notepad not open"); } } }