Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

String dataFields is read from input. dataFields contains values delimited by dashes ( ' - ' ) . Assign thirdDash with the index of the

String dataFields is read from input. dataFields contains values delimited by dashes ('-'). Assign thirdDash with the index of the third occurrence of a dash ('-') in dataFields.
Ex: If the input is John-Parvati-Ralitza-Fatima-Carlos, then the output is:
First three fields: John-Parvati-Ralitza
import java.util.Scanner;
public class FirstThreeFields {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
String dataFields;
int i;
int freqOccurred =0;
int thirdDash =-1;
dataFields = scnr.nextLine();
/* Your code goes here */
System.out.println("First three fields: "+ dataFields.substring(0, thirdDash));
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions

Question

Which form of proof do you find least persuasive? Why?

Answered: 1 week ago