Monday, 6 November 2017

java important input output problems



Question 01
What is the output of the following:
System.out.println("1" + 1);
System.out.println('1' + 1);
System.out.println("1" + 1 + 1);
System.out.println("1" + (1 + 1));
System.out.println('1' + 1 + 1);
Output
Output is 11
                  50
                   111
                    12
                   51


Question 02
What is the output of the following:
System.out.println("1" + 1+3);
System.out.println('1' + 1*3);
System.out.println("1" + 1 *4+4+ 1);
System.out.println("1" + 4+(1 + 1));
System.out.println('1' + (1+3) + 1);
 }
Output
Output is
113
52
1441
142
54

java methods



Question 30
What is equals()
 Ans
It compare two strings and it is case sensitive
Question 31
What is equalsIgnoreCase()
 Ans
This function compare two strings but it is not case sensitive.
Question 32
Give example of equals()
 Ans
String s1="this4is4my4book";
String s2="this4is4my4book";
String s3="lkajfslagj;fklgja";
System.out.println(s1.equals(s2));  //true
 System.out.println(s3.equals(s2));  //false
Question 33
Give example of equalsIgnoreCase()
 Ans
String s1="thIs4is4My4book";
String s2="This4is4my4Book";
String s3="lkajfslagj;fklgja";
System.out.println(s1.equalsIgnoreCase(s2));  //true
 System.out.println(s3.equals(s2));               // false

java theory



Question 22
What is toLowerCase();
Ans
It convert upper case into lower case.
 Question 23
Give  example of  toLowerCase()
Ans

Example      Charater.toLowerCase(P)   it returns  p
Question 24
What is trim()
Ans
The void space is removed from both sides using trim().
Question 25
Give example of trim()
Ans
It "\t Good Night \n".trim() returns a new string Good Night.
Question 26
What is length()
Ans
It is used to calculate to number of character in a string
Question 27
Give example of  length
Ans
String d=”This is my book and”,
System.out.println(d.length());    it returns 19
Question 28
What is indexOf()
Ans
It is used to check the index number of character
 Question 29
Give example indexOf()
Ans
"Welcome to Java".indexOf('o') returns 4.

java important theory problems



Question 16
What is isUpperCase();
Ans
It work on single character. This function return true or false. If user enter character in upper case returns true otherwise it returns false
Question 17
Give example of isUpperCase();
Ans
Example       Character.isUpperCase(A)    returns true  Character.isUpperCase(s)
Returns false.
Question 18
What is isLowerCase();
Ans
It work on single character. This function return true or false. If user enter character in lower case returns true otherwise it returns false
Question 19
Give examples of  isLowercase()
Ans
Example       Character.isLowerCase(s)    returns true  Character.isLowerCase(A)
Returns false.
Question 20
What is toUpperCase();
Ans
It convert lowercase into upper case.
Question 21
Give example of toUpperCase();
Ans
Example      Charater.toUpperCase(a)   it returns  A