Advertisement
SergeyPGUTI

7.2.8

Nov 26th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.  
  4.  
  5.     static void  MaxWord(String a)
  6.     {
  7.         a=a+' ';// пробел в конец слова
  8.         int MaxLength=0;
  9.         int EndPosition=0;
  10.         for (int i=0,Length=a.length(),WordLength=0;i<Length;i++)
  11.         {
  12.             if (a.charAt(i)!=' ') WordLength++;
  13.             if (a.charAt(i)==' ')
  14.             {
  15.                 if (WordLength>MaxLength)
  16.                 {
  17.                     MaxLength=WordLength;
  18.                     EndPosition=i;
  19.                 }
  20.                 WordLength = 0;
  21.             }
  22.         }
  23.         System.out.print(MaxLength+" ");
  24.         for (int i=(EndPosition-MaxLength);i<EndPosition;i++)
  25.         {
  26.             System.out.print(a.charAt(i));
  27.         }
  28.     }
  29.  
  30.     public static void main(String[] args) {
  31.         Scanner in = new Scanner(System.in);
  32.         String a=in.nextLine();
  33.         MaxWord(a);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement