Untitled
unknown
plain_text
2 years ago
2.1 kB
6
Indexable
import java.util.Scanner; public class ParseTheTweet { public static void main(String[] args) { // Declare Scanner Scanner keyboard = new Scanner(System.in); // Declare Variables String type, detail, location, latitude, longitude; int start, finish; // Input your tweet System.out.print("Enter your tweet here: "); String tweet = keyboard.nextLine(); // Define indices for # and ; (start and finish) start = tweet.indexOf("#typ") + 5; //Start at #, overlook 3 letters and space to start at user input value finish = tweet.indexOf(";"); type = tweet.substring(start, finish); //Pulling out SubString type = type.trim(); //Trimming SubString type = type.toUpperCase(); // Making the substring in all capital letters tweet = tweet.substring(finish + 1); //Redefining tweet to discard earlier values // Redefining start, finish, and tweet for new values of detail start = tweet.indexOf("#det") + 5; finish = tweet.indexOf(";"); detail = tweet.substring(start, finish); detail = detail.replace(',', '-'); // replacing , with - detail = detail.trim(); tweet = tweet.substring(finish + 1); // Location start = tweet.indexOf("#loc") + 5; finish = tweet.indexOf(";"); location = tweet.substring(start, finish); detail = detail.replace(',', '-'); location = location.trim(); tweet = tweet.substring(finish +1); // Latitude start = tweet.indexOf("#lat") + 5; finish = tweet.indexOf(";"); latitude = tweet.substring(start, finish); latitude = latitude.trim(); tweet = tweet.substring(finish + 1); // Longitude start = tweet.indexOf("#lng") + 5; finish = tweet.indexOf(";"); longitude = tweet.substring(start, finish); longitude = longitude.trim(); tweet = tweet.substring(finish + 1); // Printing Outputs System.out.println("Type:\t\t" + type); System.out.println("Detail:\t\t" + detail); System.out.println("Location:\t" + location); System.out.println("Latitude:\t" + latitude); System.out.println("Longitude:\t" + longitude); keyboard.close(); } }
Editor is loading...