Computer Applications
Cyber police wanted to investigate a case; they wanted to check a list of phone numbers that had 945 anywhere in the phone number. Example: 7394567938, 7685483945.., a method was created to convert the phone number in long data type to a string and check for the existence of the number 945. Fill in the blanks (a) and (b) in the given method with appropriate Java statements:
void check(long pno)
{ String s = _______(a)_________;
if(______(b)_______)
System.out.println(pno);
}
Java String Handling
15 Likes
Answer
void check(long pno)
{ String s = String.valueOf(pno);
if(s.indexOf("945") >= 0)
System.out.println(pno);
}
Answered By
9 Likes
Related Questions
Name the following:
(a) Method with the same name as of the class and is invoked every time an object is created.
(b) Keyword to access the classes of a package.Name the following:
(a) A Character method that checks whether a character is an alphabet or a number.
(b) A Math method that does not have an argument.A manager wants to check the number of employees with names ending with KUMAR, and fill in the blanks in the given program segment with appropriate Java statements:
void count(String s[]) { int i, l=_________, c=0; for(i=0;i<l;i++) { if(________________) c++; } System.out.println(c); }The output of a program which extracts a part of the string "COMPASSION" is as follows:
(a) "PASS"
(b) "PASSION"Write appropriate Java statements to get the above outputs.