Computer Science, asked by AdithyaDS5817, 9 months ago

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

Answers

Answered by zainsyed
0

Answer:

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

\1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

1).Write a program to accept a sentence and display the longest word in the sentence? (Scanner class)

Explanation:

Answered by hoangmustang
0

Answer:

Check out my solution!

package newPack;

import java.util.*;

public class longestWord {

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

String word = input.nextLine();

int length = 0;//we need to set this value = 0 to find the largest value

String [] s = word.split(" ");//divide the sentence into parts by space and store into String array

String longestWord = "";

for(int i = 0; i < s.length; i++) {

if(s[i].length() > length) {

 length = s[i].length();

 longestWord = s[i];

}

}

System.out.println(longestWord);

}

}

Explanation:

Similar questions