-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
36 lines (22 loc) · 736 Bytes
/
Copy pathMain.java
File metadata and controls
36 lines (22 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.company;
import java.util.Scanner;
//Longest String
public class Main {
static String longStr( String val){
String bigWord = "";
String[] arrStr = val.split ( " " );
for (int i = 0; i < arrStr.length; i++) {
if (arrStr[i].length () > bigWord.length ()){
bigWord = arrStr[i];
}
}
String word = "\"%s\" has letters in it %s".formatted ( bigWord,bigWord.length () );
return word;
}
public static void main(String[] args) {
Scanner sentence = new
Scanner ( System.in );
System.out.print ( "Please write a sentence " );
System.out.println (longStr (sentence.next()));
}
}