Input and Output Array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NandiniJoshi
    New Member
    • Jul 2021
    • 1

    Input and Output Array

    Question:Input
    2
    5
    1 2 3 4 5
    7
    5 1 4 6 8 1 4
    Output
    1 2 3 4 5
    5 1 4 6 8 1 4
    import java.util.*;
    import java.io.*;

    public class Main {
    public static void main(String args[]) throws IOException {
    Scanner sc= new Scanner(System. in);
    int T=sc.nextInt();
    for(int i=0;i<T;i++)
    {
    int n=sc.nextInt();
    int arr[]= new int[n];
    for(int j=0;j<n;j++)
    arr[j]=sc.nextInt();
    for(int j=0;j<n;j++)
    System.out.prin tln(arr[j]);
    }
    }
    }

    Output
    1 2 3 4 5 5 1 4 6 8 1 4


    How can i get correct output here?
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    Question:Input
    2
    5
    1 2 3 4 5
    7
    5 1 4 6 8 1 4
    Output
    1 2 3 4 5
    5 1 4 6 8 1 4
    import java.util.*;
    import java.io.*;

    public class Main {
    public static void main(String args[]) throws IOException {
    Scanner sc= new Scanner(System. in);
    int T=sc.nextInt();
    for(int i=0;i<T;i++)
    {
    int n=sc.nextInt();
    int arr[]= new int[n];
    for(int j=0;j<n;j++)
    arr[j]=sc.nextInt();
    for(int j=0;j<n;j++)
    System.out.prin tln(arr[j]);
    }
    }
    }

    Output
    1 2 3 4 5 5 1 4 6 8 1 4


    How can i get correct output here?
    How can you have a single line using println()?
    Code:
                ...
                for (int j = 0; j < n; j++)
                    System.out.print(arr[j] + " ");
                System.out.println();
            }
        }
    }

    Comment

    • priti kumari
      New Member
      • Jul 2021
      • 3

      #3
      Question:input
      2
      5
      12345
      7
      5146814
      output
      12345
      5146814
      import java.util*;
      import java.!o.*;
      publish class main{
      publish static void main(string args[])throws 10 exception{
      scanner s=new scanner(system. in);
      int T=s.next int();
      for(int!=o;!<T; i++
      {
      int n=s.next int();
      int arr[]=new int [n];
      for(int j=o;j<n;j++)
      system.out.prin t.in(arr[j])
      {
      }
      {
      output
      123455146814

      Comment

      • dev7060
        Recognized Expert Contributor
        • Mar 2017
        • 656

        #4
        priti kumari:
        Question:input
        2
        5
        12345
        7
        5146814
        output
        12345
        5146814
        Code:
        import java.util*;
        import java.!o.*;
        publish class main{
        publish static void main(string args[])throws 10 exception{
        scanner s=new scanner(system.in);
        int T=s.next int();
        for(int!=o;!<T;i++
        {
        int n=s.next int();
        int arr[]=new int [n];
        for(int j=o;j<n;j++)
        system.out.print.in(arr[j])
        {
        }
        {
        output
        123455146814
        Did you try compiling the code? I can see countless errors already.

        Comment

        Working...