Java Array Question
Okay, I have added comments to explain what i am doing inside the program. I cannot figure out the last one in which i have to display the array backwards. If you can provide any insight as into what i am overlooking it would be of great help. Also if you could suggest a way to format the code so that when executed the stuff is not so close together, it would be greatly appreciated as well.
sorry forgot to post the code
import java.util.Scanner;
public class AlphaArray {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
char[] alphabet = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//display Array
System.out.println("The Array is= ");
System.out.println(alphabet);
//display first ten
System.out.println("The first ten are= ");
double firstTen = 0;
for (int i=0; i <10;i++){
System.out.print(alphabet[i]+"");
}
//display last 6
System.out.println("\nThe last six are= ");
double lastSix = 20;
for (int i=0; i<26;i++){
System.out.print(alphabet[i]+"");
}
//diplay 9th
System.out.println("\nThe ninth index is= ");
System.out.println(alphabet[9]);
//display revers index
System.out.println("\nThe reverse order is= ");
double reverse= 26;
for (int i=26; i>0;i--){
System.out.print(alphabet[i]+"");
}
}
}
> try this
>
> > for (int i=25; i>=0;i--)
> {
> System.out.print(alphabet[i]+"");
> }
>
How can I missed that :(
But it would be better to use alphabet.length -1 instead of 25
And for the 2nd method, it should print out last six elements but not all