A blog which has various codes and other descriptions from all fields of Computer Science and other domains.
Wednesday, 21 December 2016
Difference between Procedure Oriented Languages and Object Oriented Languages.
Friday, 4 November 2016
Wednesday, 2 November 2016
Sunday, 15 May 2016
Java code to check whether a number is power of two
import java.util.Scanner;
public class CheckPowerTwo {
public static void main(String args[])
{
Scanner ob= new Scanner(System.in);
int a,i;
System.out.println("Enter an integer");
a=ob.nextInt();
for( i=0;i<a;i++)
{
if(a==Math.pow(2,i))
{ System.out.println("The number is power of two");break;
}
}
if(i==a)
System.out.println("The number is not power of two");
}
}
Reading a file using FileInputStream in java
import java.io.FileInputStream;
public class ReadFile {
public static void main(String args[])
{ FileInputStream fin ;
try{
fin= new FileInputStream("C:\\Users\\user\\Desktop\\ash.txt");
int c;
while((c=fin.read())!=-1)
{
System.out.print((char)c);
}
}
catch(Exception e){}
}
}