×

Java Programs

Java Practice

Java program to convert an integer array into the string using the '+' operator

Given/input an integer array, we have to convert it into the string using the "+" operator.
Submitted by Nidhi, on March 15, 2022

Problem statement

In this program, we will create an array of integers. Then we will convert the array into a string.

Java program to convert an integer array into the string using the '+' operator

The source code to convert an integer array into the string using the "+" operator is given below. The given program is compiled and executed successfully.

// Java program to convert an integer array into 
// the string using the "+" operator

import java.util.Arrays;

public class Main {
  public static void main(String[] args) {
    int i;
    String str = "";
    int[] arr = {53, 7, 64, 1, 9};

    for (i = 0; i < arr.length; i++) {
      str += arr[i];
    }

    System.out.println(str);
  }
}

Output

5376419

Explanation

In the above program, we imported java.util.Scanner to read input from the user. And, created a Main class that contains a method main().

The main() method is the entry point for the program, here we created an integer array arr and converted the created array into the string using concatenation, and printed the result.

Java Conversion Programs »





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.