Read short from file using DataInputStream
import
java.io.DataInputStream;
import
java.io.FileInputStream;
import java.io.FileNotFoundException;
import
java.io.IOException;
public class
ReadShortFromFile
{
public static void
main(String[] args)
{
String
strFilePath = "C://FileIO//readShort.txt";
try
{
FileInputStream fin =
new FileInputStream(strFilePath);
DataInputStream din =
new DataInputStream(fin);
short s =
din.readShort();
System.out.println("short
: " + s);
din.close();
}
catch(FileNotFoundException
fe)
{
System.out.println("FileNotFoundException
: " + fe);
}
catch(IOException ioe)
{
System.out.println("IOException
: " + ioe);
}
}
}
Java String isEmpty
public class
JavaStringIsEmptyExample
{
public static void
main(String args[])
{
String str1 =
"";
String str2 = null;
String str3 =
"Hello World";
System.out.println("Is
String 1 empty? :" + str1.isEmpty()); System.out.println("Is String 3
empty? :" + str3.isEmpty());
}
}
Java float
import java.util.*;
public class
JavaFloatExample
{
public static void
main(String[] args)
{
float = ;
float f = 10.4f;
System.out.println("Value
of float variable f is :" + f);
}
}
Compare Two Numbers
public class
CompareTwoNumbers
{
public static void
main(String[] args)
{
int num1 = 324;
int num2 = 234;
if(num1 > num2)
{
System.out.println(num1
+ " is greater than " + num2);
}
else if(num1 <
num2)
{
System.out.println(num1
+ " is less than " + num2);
}
else
{
System.out.println(num1
+ " is equal to " + num2);
}
}
}
No comments:
Post a Comment