Files and I/O
- What is the output of this program?
public class output
{
public static void main(String args[])
{
StringBuffer s1 = new StringBuffer("Interview");
s1.setCharAt(8,'W');
System.out.println(s1);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
IntervieW
- What is the output of this program?
public class IndexOf_Example
{
public static void main(String args[])
{
String str="My first love is java.";
System.out.println(str.indexOf('i')+" "+str.indexOf('o')+" "+str.lastIndexOf('i')+" "+str.lastIndexOf('j') );
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
indexof(‘c’) and lastIndexOf(‘j’) are pre defined function which are used to get the index of first and last occurrence of
the character pointed by j in the given array.
- What is the output of this program?
public class Result
{
public static void main(String args[])
{
char array[]={'a','1','b',' ','A','0'};
for (int k = 0; k < 5; ++k)
{
if(Character.isDigit(array[k]))
System.out.println(array[k]+" is a digit");
if(Character.isWhitespace(array[k]))
System.out.println(array[k]+" is a Whitespace character");
if(Character.isUpperCase(array[k]))
System.out.println(array[k]+" is an Upper case Letter");
if(Character.isLowerCase(array[k]))
System.out.println(array[k]+" is a lower case Letter");
k = k + 3;
}
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Character.isDigit(array[k]),Character.isUpperCase(array[k]),Character.isWhitespace(array[k]) are the function of library java.lang
they are used to find weather the given character is of specified type or not. They return true or false i:e Boolean variable.
- What is the output of this program?
public class Result
{
public static void main(String args[])
{
StringBuffer strbuf = new StringBuffer("Interview Mania");
StringBuffer strbuf0 = strbuf.reverse();
System.out.println(strbuf0);
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
reverse() method reverses all characters. It returns the reversed object on which it was called.
- What is the output of this program?
import java.io.*;
public class InputStream_Example
{
public static void main(String args[]) throws IOException
{
InputStream obj = new FileInputStream("Interviewmania.com");
System.out.print(obj.available());
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Exception in thread "main" java.io.FileNotFoundException: Interviewmania.com (No such file or directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.(FileInputStream.java:138)
at java.io.FileInputStream.(FileInputStream.java:93)
at InputStream_Example.main(InputStream_Example.java:6)