This is a question about how to use a String in a Java Array basic example!

Asked 2 years ago, Updated 2 years ago, 64 views

package practice_3;
import javax.swing.JOptionPane;


public class ArrayTest {
public static void main(String[]args) {
    String output = "";
    int n[] = new int[10];

    output += "subscript | value\n";

    for (int i = 0; i< n.length; i++) {
        output +=+i+ " | " + n[i] + "\n";

    }
    JOptionPane.showMessageDialog(null, output);
    System.exit(0);


}

Everything is fine in this code, output +=+i+" | " + n[i] + "\n";

I wonder why I should use output +=+i in this part.

Can't I just use output + i or output + = i?

java array string

2022-09-22 19:05

1 Answers

Available.

output += i + " | " + n[i] + "\n";

output += + i + " | " + n[i] + "\n";

We've seen that both have the same output.

output += .... It's all

output = output + .... I don't know why I wrote "+" in the beginning.


2022-09-22 19:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.