osheen.just.me
| Subject: plzz help Fri Jul 04, 2008 7:44 pm | |
| w.a.p to store 20 different names in a single dimensional array . display only those names whose first character matches with the character entered by the user. |
|
abhas Active member
| Subject: isc jdk java string program Tue Jul 08, 2008 9:47 pm | |
| //here is the answer import java.io.*; class Sprog { public static void main(String args[]) throws IOException { BufferedReader obj=new BufferedReader(new InputStreamReader(System.in)); String arr[]=new String[20]; String ar[]=new String[20]; int x=0; System.out.println("Enter character"); String a=obj.readLine();
for(int c=0;c<20;c++) { System.out.println("Enter Name"); arr[c]=obj.readLine(); arr[c]=arr[c].toLowerCase(); a=a.toLowerCase(); if (arr[c].charAt(0)==a.charAt(0) ) { ar[x]=arr[c]; x++; } }
for(int d=0;d<x;d++) { System.out.println(ar[d]); } } }
// this is one of the many possible ways to do the program... //you may have to change it slightly so as to make it work on bluej |
|