I want to have a program that takes a string, splits it at a space, and prints the length of the smallest substring.
I wrote this but it just prints the length of the first string. What is my problem ?
Scanner input = new Scanner(System.in);
String inp = input.nextLine();
int counter = 0;
String[]helper =new String[inp.length()];
int minlength = Integer.MAX_VALUE;
for (int i = 0; i < inp.length(); i++)
{
if (inp.charAt(i) != ' ')
{
counter++;
continue;
}
minlength = Math.min(counter, minlength);
counter = 0;
}
System.out.println(minlength);