nitish_mythology
OSS Enthusiast!
I tried to make a prg to find the largest word in a string but was unable.
I ended up with this.Can anyone tell my mistakes and write the correct prg!!
import java.io.*;
class lar_str
{
public static void main(String args[]) throws IOException
{
String str;
char arr[]=new char[50];
int bp[]=new int[50];
int lp[]=new int[50];
int len[]=new int[50];
int c,l;
int bep=0;
InputStreamReader rd=new InputStreamReader(System.in);
BufferedReader inp=new BufferedReader(rd);
System.out.println("Enter the String");
str=inp.readLine();
l=str.length();
str.getChars(1,l,arr,0);
for(c=0;c<l;c++)
{
bp[c]=bep;
while(arr[bep]!=' ')
{
bep++;
}
len[c]=bep-bp[c];
lp[c]=bep;
}
int search_add=len[0];
for(c=0;c<len.length;c++)
{
if(len[c]>search_add)
search_add=c;
}
char fin[]=new char[50];
int k=0;
for(c=bp[search_add];c<=lp[search_add];c++)
{
fin[k]=arr[c];
k++;
}
System.out.println(fin);
}
}
I ended up with this.Can anyone tell my mistakes and write the correct prg!!
import java.io.*;
class lar_str
{
public static void main(String args[]) throws IOException
{
String str;
char arr[]=new char[50];
int bp[]=new int[50];
int lp[]=new int[50];
int len[]=new int[50];
int c,l;
int bep=0;
InputStreamReader rd=new InputStreamReader(System.in);
BufferedReader inp=new BufferedReader(rd);
System.out.println("Enter the String");
str=inp.readLine();
l=str.length();
str.getChars(1,l,arr,0);
for(c=0;c<l;c++)
{
bp[c]=bep;
while(arr[bep]!=' ')
{
bep++;
}
len[c]=bep-bp[c];
lp[c]=bep;
}
int search_add=len[0];
for(c=0;c<len.length;c++)
{
if(len[c]>search_add)
search_add=c;
}
char fin[]=new char[50];
int k=0;
for(c=bp[search_add];c<=lp[search_add];c++)
{
fin[k]=arr[c];
k++;
}
System.out.println(fin);
}
}