Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- static void MaxWord(String a)
- {
- a=a+' ';// пробел в конец слова
- int MaxLength=0;
- int EndPosition=0;
- for (int i=0,Length=a.length(),WordLength=0;i<Length;i++)
- {
- if (a.charAt(i)!=' ') WordLength++;
- if (a.charAt(i)==' ')
- {
- if (WordLength>MaxLength)
- {
- MaxLength=WordLength;
- EndPosition=i;
- }
- WordLength = 0;
- }
- }
- System.out.print(MaxLength+" ");
- for (int i=(EndPosition-MaxLength);i<EndPosition;i++)
- {
- System.out.print(a.charAt(i));
- }
- }
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- String a=in.nextLine();
- MaxWord(a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement