Sample Input Happy new year Sample Output Word with max vowels Year.. using scanner class please
Answers
Answered by
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);
}
}
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
Answered by
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