If i gave 1character the name start wth that characteer has to be displayed... using java
import javax.swing.*; class Name { public static void main (String arg[]) { String st=JOptionPane.showInputDialog(null,"Enter any character"); char ch=st.charAt(0); switch(ch) { case 'A': JOptionPane.showMessageDialog(null,"Ali\n Azam\n Afzal\n"); break; case 'B': JOptionPane.showMessageDialog(null,"Babar\n Bebo\n Bell\n"); break; default: JOptionPane.showMessageDialog(null,"Invalid"); } } }
import java.util.*; class DisplaySetOfNames{ public static void main(String[] args) { String[] countries = {"Afghanistan", "Albania", "Algeria", "Andorra", "Angola","Argentina" ,"Armenia","Austria","Bahamas","Bahrain", "Bangladesh","Barbados", "Belarus","Belgium", "Benin","Bhutan","Bolivia","Bosnia & Herzegovina","Botswana","Brazil","Bulgaria", "Burkina Faso","Burma","Burundi","Cambodia","Cameroon","Canada", "China","Colombia", "Comoros","Congo","Croatia","Cuba","Cyprus","Czech Republic","Denmark", "Georgia", "Germany","Ghana","Great Britain","Greece","Hungary","Holland","India","Iran","Iraq", "Italy","Somalia", "Spain", "Sri Lanka", "Sudan","Suriname", "Swaziland","Sweden", "Switzerland", "Syria","Uganda","Ukraine","United Arab Emirates","United Kingdom", "United States","Uruguay","Uzbekistan","Vanuatu","Venezuela","Vietnam", "Yemen","Zaire","Zambia","Zimbabwe"}; Scanner input=new Scanner(System.in); System.out.print("Enter letter: "); String letter=input.next().substring(0,1); System.out.println(); for(int i=0;i<countries.length;i++){ if(countries[i].startsWith(letter)){ System.out.println(countries[i]); } } } }
import java.util.*; class DisplaySetOfNames{ public static void main(String[] args) { String[] countries = {"Afghanistan", "Albania", "Algeria", "Andorra", "Angola","Argentina" ,"Armenia","Austria","Bahamas","Bahrain", "Bangladesh","Barbados", "Belarus","Belgium", "Benin","Bhutan","Bolivia","Bosnia & Herzegovina","Botswana","Brazil","Bulgaria", "Burkina Faso","Burma","Burundi","Cambodia","Cameroon","Canada", "China","Colombia", "Comoros","Congo","Croatia","Cuba","Cyprus","Czech Republic","Denmark", "Georgia", "Germany","Ghana","Great Britain","Greece","Hungary","Holland","India","Iran","Iraq", "Italy","Somalia", "Spain", "Sri Lanka", "Sudan","Suriname", "Swaziland","Sweden", "Switzerland", "Syria","Uganda","Ukraine","United Arab Emirates","United Kingdom", "United States","Uruguay","Uzbekistan","Vanuatu","Venezuela","Vietnam", "Yemen","Zaire","Zambia","Zimbabwe"}; Scanner input=new Scanner(System.in); System.out.print("Enter letter: "); String letter=input.next().substring(0,1); System.out.println(); for(int i=0;i<countries.length;i++){ if(countries[i].startsWith(letter)){ System.out.println(countries[i]); } } } }
Ads