0

Write a program in Java to store 10 different words in a Single Dimensional array. Perform the following tasks.

(i) Extract and store all VC words (Only those words starting with Vowel and ending with consonant) in a Single Dimensional Array named VC[ ]. Print all VC words. (ii) Extract and store all CV words(Only those words starting with Consonants and ending with Vowel) in a Single Dimensional Array named CV[ ].Print all CV words. (iii) Store other words(Words don't belong to above two categories) in a Single Dimensional Array named OTH[ ]. Print Other words.

28th Oct 2022, 11:43 AM
Javgeek
Javgeek - avatar
3 odpowiedzi
+ 3
That's a cool task. Are you having trouble with it? Please share your code here and maybe someone can help you.
28th Oct 2022, 1:08 PM
Ausgrindtube
Ausgrindtube - avatar
+ 3
Perhaps this will help you with your arrays https://www.w3schools.com/java/java_arrays.asp For the logic, I think you might be best doing everything in simpler steps. Take all 10 inputs. You pretty much have that. for(int a = 0; a <= 10; a++) { ar[a] = in.nextLine(); } Iterate through this array, get the length and check your first and last letters. If they match the condition, put them into the new corresponding array. Print each array.
28th Oct 2022, 3:05 PM
Ausgrindtube
Ausgrindtube - avatar
0
import java.util.*; public class Assign25_V { public static void main(String[] args) { Scanner in=new Scanner (System.in); String ar[]=new Line[10]; String V[5]={A,E,I,O,U,a,e,i,o,u}; String C[21]={B,C,D,F,G,H,J,K,L,M,N,P,Q,R,S,T,V,W,X,Y,Z,b,c,d,f,g,h,j,k,l,m,n,p,q,r,r,s,t,v,w,x,y,z}; int i; for (i=0;i<=10;i++) { ar[i]=in.nextLine(); String s=ar[i]; int len=s.length(); char fch=s.charAt(0); char lch=s.charAt(s.length); } for (i=0;i<=len;i++) { if (fch==V[5] && lch==C[21]) System.out.print ("VC Words:" +s+" "); if (fch==C[21] && lch==V[5]) System.out.print ("CV Words:" +s+" "); else System.out.print ("Other Words:" +s+" ") } } } I am facing syntax errors
28th Oct 2022, 1:17 PM
Javgeek
Javgeek - avatar