- 2

Array

create a Strung array with spaces and in the console output an array without spaces: example {a, b, -, c, -, f}; and on the output so that it turns out like this {a, b, c, f}. without spaces https://code.sololearn.com/cf1QdQX2nycx/?ref=app

9th Jul 2021, 10:33 AM
Best of Sport
Best of Sport - avatar
1 Answer
0
import java.util.Scanner; public class Array21{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); String[] array = new String[5]; String[] array2 = new String[array.length]; for (int i = 0; i<array.length; i++){ String scanArray = scan.nextLine(); array[i] = scanArray; System .out.println(array[i]); } //array = array2; thIs creates all your input into array will make empty ,null values of array2, so remove . for (int k = 0; k<array.length; k++){ if (!array[k].equals(" ")){ System.out.print(array[k] + ","); } } } } //error removed //== compares string reference not values or content. use equal() method for String value comparisions...
9th Jul 2021, 12:50 PM
Jayakrishna 🇼🇳