Search code examples
javaarraysuser-inputreadlineeof

How can I take string input for UVA online problem for java only ? Detail information needed


I am trying to string input for UVA online judge problem using JAVA.

like C++

while(s = getchar()) {
   if(s == EOF)
}

Solution

  • import java.util.Scanner;
    
    Scanner scanner = new Scanner(System.in);
    System.out.println("Enter a string.");
    String str = scanner.nextLine();
    

    Is this what you're looking for? If you're reading from a file,

    import java.io.File;
    
    Scanner scanner = new Scanner(new File("path.txt"));
    while (scanner.hasNextLine()) {
        String str = scanner.nextLine();
        //...
    }