Answer to Question #323295 in Java | JSP | JSF for asdihvsad

Question #323295

Quite tiring to write those things separated by commas and a single space, isn't it?

Then let's try coding it instead

Five lines containing a string on each.

A single line containing all the strings separated by a comma and a space.


1
Expert's answer
2022-04-04T16:12:05-0400
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        String[] arr = new String[5];
        String answ = "";

        for(int i = 0; i < arr.length; i++) {
            System.out.print("Enter line " + (i+1) + ": ");
            arr[i] = in.nextLine();
        }

        for(int i = 0; i < arr.length; i++){
            if(i == arr.length-1){
                answ += arr[i] + ".";
                continue;
            }
            answ += arr[i] + ", ";
        }
        System.out.println(answ);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS