How can we add two array?

How do you go back to the start of an array in Java?

  • In this program the user will input a letter, and the program will tell you what letter comes next. I am only going up to letter F. String letter[] = {"A", "B", "C", "D", "E", "F"}; for (int i=0; i<letter.length; i++) { System.out.println("Two letters later is" + letter[i+2]); } The problem is that at letter F you can't add another letter because that's the end of the array. How do I get it to go back to the start of the array using an "if" statement? So that if the user inputs F, the program will give out A?

  • Answer:

    You could add an extra "A" at the end of the string array, then only loop up to (letter.length - 1).

1two3 at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Question: your explanation says "the program will tell you what letter comes NEXT" but.. your code says "Two letters later"... which one is it? If possible show the whole code. well here is my suggestion: --------------------------------------… you first need to define the input mechanism (i.e) BufferedReader --------------------------------------… BufferedReader buf_in = new BufferedReader (new InputStreamReader (System.in)); String input = " "; input = buf_in.readline() ; String letter[] = {"A","B","C","D","E","F"} ; for (int i=0; i< letter.length, i++) ; { if (input.toUppercase.equals(letter[i]) { if (i==(letter.length-1) System.out.println ("One letter later is "+letter[0]) ; else system.out.println ("One letter later is " +letter[i+1]) ; } }

Or don't use a for loop.

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.