Get reliable answers to your questions at Westonci.ca, where our knowledgeable community is always ready to help. Experience the ease of finding reliable answers to your questions from a vast community of knowledgeable experts. Join our Q&A platform to connect with experts dedicated to providing accurate answers to your questions in various fields.

Strings batch1 and batch2 are read from input. Each string consists of at least two foods, separated by " " and surrounded by "[" and "]". Assign firstItems with the first food from each string, separated by " ".

Ex: If the input is:

[peach bread lemon]
[pear carrot cheese]
then the output is:

import java.util.Scanner;

public class JoinMultipleFirsts {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String batch1;
String batch2;
String firstOfBatch1;
String firstOfBatch2;
String firstItems;

batch1 = scnr.nextLine();
batch2 = scnr.nextLine();

int startIndex = batch1.lastIndexOf(' ') + 1;

int endIndex = batch1.length() - 1;

firstOfBatch1 = batch1.substring(startIndex, endIndex);


startIndex = batch2.lastIndexOf(' ') + 1;

endIndex = batch2.length() - 1;

firstOfBatch2 = batch2.substring(startIndex, endIndex);

firstItems = firstOfBatch1 + " " + firstOfBatch2;

System.out.println(firstItems);
}
}



Sagot :

We appreciate your time. Please revisit us for more reliable answers to any questions you may have. Thanks for stopping by. We strive to provide the best answers for all your questions. See you again soon. Stay curious and keep coming back to Westonci.ca for answers to all your burning questions.