Input a string in java and print its first and last word. its java btw
Attachments:
Answers
Answered by
1
Answer:
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] str = br.readLine().trim().split("\\s+");
System.out.println("First word is: " + str[0] + "\n" + "Last Word: " + str[str.length - 1]);
}
}
Similar questions