Computer Science, asked by Satan2002, 1 year ago

Sample Input Happy new year Sample Output Word with max vowels Year.. using scanner class please

Answers

Answered by Vintage
2
import java.util.Scanner;
public class Extra
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
String s,wd="",lwd="";
int i,j,ctr=0,max=0;
System.out.print("Enter the sentence:- ");
s=sc.nextLine()+" ";
for(i=0;i<s.length();i++)
if(s.charAt(i)!=' ')
wd+=s.charAt(i);
else
{
for(j=0;j<wd.length();j++)
if("AEIOUaeiou".indexOf(s.charAt(j))>=0)
ctr++;
if(ctr>max)
{
max=ctr;
lwd=wd;
}
wd="";
}
System.out.println("Word with maximum vowels is:- "+lwd);
}
}

Satan2002: can you help me with the logic portion
Vintage: wait
Vintage: see first we form the seperate words one by one through the if block and then the word limit is checked in the else block
Vintage: and at last it is printed
Satan2002: OK... u from
Vintage: plz mark brainliest
Answered by acsahjosemon40
0

Answer:

import java.util.Scanner;

public class Extra

{

public static void main(String args[])

{

Scanner sc = new Scanner(System.in);

String s,wd="",lwd="";

int i,j,ctr=0,max=0;

System.out.print("Enter the sentence:- ");

s=sc.nextLine()+" ";

for(i=0;i<s.length();i++)

if(s.charAt(i)!=' ')

wd+=s.charAt(i);

else

{

for(j=0;j<wd.length();j++)

if("AEIOUaeiou".indexOf(s.charAt(j))>=0)

ctr++;

if(ctr>max)

{

max=ctr;

lwd=wd;

}

wd="";

}

System.out.println("Word with maximum vowels is:- "+lwd);

}

}

Similar questions