TESTCASE 1 and TESTCASE 2 are not working.
Can you please correct me?
CanYouReadThis JAVA STRINGS
We may pass an object of class File if we want to read input from a file. To read strings, we use nextLine(). To read a single character, we use next().charAt(0).
next() function returns the next token/word in the input as a string and charAt(0) function returns the first character in that string.
If you want to scan then use:
import java.util.*;
public class ScannerExample {
public static void main(String args[]){
Scanner in = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = in.nextLine();
System.out.println("Name is: " + name);
in.close();
}
}
Output:
Enter your name: Ria Singh
Name is: Ria Singh