Computer Applications
Give the output of the following string functions:
"DEDICATE".compareTo("DEVOTE")
Java
Java String Handling
ICSE 2018
93 Likes
Answer
-18
Working
"DEDICATE" and "DEVOTE" differ at the third character with 'D' and 'V', respectively. So, output of compareTo()
method will be ASCII Code of 'D' - ASCII Code of 'V' ⇒ 68 - 86 ⇒ -18.
Answered By
55 Likes
Related Questions
Give the output of the following statements:
String x[] = {"SAMSUNG", "NOKIA", "SONY", "MICROMAX", "BLACKBERRY"};
System.out.println(x[3].length());
Give the output of the following string functions:
"ACHIEVEMENT".replace('E', 'A')Consider the following String array and give the output
String arr[]= {"DELHI", "CHENNAI", "MUMBAI", "LUCKNOW", "JAIPUR"}; System.out.println(arr[0].length() > arr[3].length()); System.out.print(arr[4].substring(0,3));
Your friend is trying to write a program to find and display the frequency of vowels in a string. Due to confusion in the syntax of some of the statements, he could not complete the program and has left some places blank marked with ?1?, ?2?, ?3? and ?4? to be filled with expression/function. The incomplete program is shown below:
import java.util.*; class Vowels { public static void main(String args[]) { Scanner ...?1?... = new Scanner(System.in); String st; int i, b, v = 0; char chr; System.out.println("Enter a string"); st = ............?2?............; // to input a string st = ............?3?...........; // to convert the string into uppercase b = st.length(); for( i = 0 ; i < b ; i++) { chr = ............?4?............; // to extract a character if(chr == 'A' || chr == 'E' || chr == 'I' || chr == 'O' || chr == 'U') v = v + 1; } System.out.println("No. of Vowels = " + v); } }
Based on the above discussion, answer the following questions:
(a) What expression/function will be filled in place of ?1?
(b) What expression/function will be filled in place of ?2?
(c) What expression/function will be filled in place of ?3?
(d) What expression/function will be filled in place of ?4?