I need to do a program that the user will input a letter from alphabet then the program will show the alphabet that starts with the inputted letter. for example
Letter: B

B C D E F G and so on..

please help me guys.. ive been doing this almost 2 days..
i really dont know what to use from array..
huhuh. please guys?

godbless!

Can you define an array of Strings: String[] anArray = new String[26]; // define array
and fill it with the letters of the alphabet? String[] anArray = {"A", "B", .. to "z");

yes. i need to declare it. i already do that but i really cant find the logic of slicing it out and displaying the letters that begin with the inputted letter. sob.

:( please help me. please :(

i really cant find the logic

Ok, we'll take it one step at a time.
Did You say that you know how to define an array and fill it with the letters?

Next Do you know how to use an index to go thru the contents of an array?
Normally this is done in a for loop.
Write a small loop in your program to go thru the array and print out the letter at each index. Only do it for 3 values, no need to show all 26.

ill make it simple..

import java.util.ArrayList;

public class Marty {


    public static void main(String[] args) {

        ArrayList<String> arrayList = new ArrayList<String>();
        arrayList.add(0, "Java");
        arrayList.add(1, "Programming");
        arrayList.add(2, "Forums");
        arrayList.add(3, ".com");

        System.out.print("Enter a word");
        //asuming that theres an bufferedreader.
}
}

     //when i enter a word from the list this will be happen:

ENTER A WORD: PROGRAMMING


//it will display the next list until the last.
OUTPUT:

Forums
.com

//i cant figure it out.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Is this a new assignment? It doesn't look anything your original problem statement that involved letters of the alphabet and arrays.
What is the definition for the problem for the code you just posted?

Edited 6 Years Ago by NormR1: n/a

A very simple way to do it would be to first, declare an array of characters that contains the alphabet e.g. char [] alphabet = {'a','b','c','d','e' .... 'y','z' };
Then make a loop that loops through the array from beginning to end.
Inside the loop write an if statement to check if the character you are currently checking is the same letter as the one the user's input.
If this is so set a flag to true.
Still inside this loop, check the flag, if it is true then print out the current character.

There are many ways you can do this. Have a go and post some code if you get stuck. People are reluctant to do your homework for you, though they are happy to help if you prove that you have tried.

Edited 6 Years Ago by bops: n/a

This article has been dead for over six months. Start a new discussion instead.