0
// Full alphabet as char
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'};
// Trying to output my first name - But result is a number
System.out.println((alphabet[13]) + (alphabet[8]) + (alphabet[10]) + (alphabet[14]) + (alphabet[18]) + (alphabet[0]));
// Output is the first letter of my first name
System.out.println(alphabet[13]);

Question: How do I output my first name using the above method with System.out.println()? Or is there a completely another way?

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
Fronin
  • 27
  • 5

2 Answers2

0

Use quotation marks:

System.out.println("" + (alphabet[13]) + (alphabet[8]) + (alphabet[10]) + (alphabet[14]) + (alphabet[18]) + (alphabet[0]));

Also, you do not need the parentheses:

System.out.println("" + alphabet[13] + alphabet[8] + alphabet[10] + alphabet[14] + alphabet[18] + alphabet[0]);
sattik
  • 71
  • 4
0

Correct syntax to build string from char aray is :

String(char[], int, int) constructor:

so use :

String s = new String(alphabet, 13, 1) + new String(alphabet, 8, 1) + new String(alphabet, 10, 1) + new String(alphabet, 14, 1)+ new String(alphabet, 18, 1) + new String(alphabet, 0, 1);
System.out.println(s);
Léo R.
  • 2,620
  • 1
  • 10
  • 22