468,743 Members | 2,015 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,743 developers. It's quick & easy.

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.println(arr[j]);
}
}
}

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


How can i get correct output here?
2 Weeks Ago #1
3 2843
dev7060
450 Expert 256MB
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.println(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()?
Expand|Select|Wrap|Line Numbers
  1.             ...
  2.             for (int j = 0; j < n; j++)
  3.                 System.out.print(arr[j] + " ");
  4.             System.out.println();
  5.         }
  6.     }
  7. }
2 Weeks Ago #2
priti kumari
3 2Bits
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.print.in(arr[j])
{
}
{
output
123455146814
2 Weeks Ago #3
dev7060
450 Expert 256MB
priti kumari:
Question:input
2
5
12345
7
5146814
output
12345
5146814
Expand|Select|Wrap|Line Numbers
  1. import java.util*;
  2. import java.!o.*;
  3. publish class main{
  4. publish static void main(string args[])throws 10 exception{
  5. scanner s=new scanner(system.in);
  6. int T=s.next int();
  7. for(int!=o;!<T;i++
  8. {
  9. int n=s.next int();
  10. int arr[]=new int [n];
  11. for(int j=o;j<n;j++)
  12. system.out.print.in(arr[j])
  13. {
  14. }
  15. {
  16.  
output
123455146814
Did you try compiling the code? I can see countless errors already.
2 Weeks Ago #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by qbschmidt | last post: by
3 posts views Thread by ES Kim | last post: by
4 posts views Thread by Jerry LeVan | last post: by
2 posts views Thread by Key9 | last post: by
4 posts views Thread by lenin42001 | last post: by
3 posts views Thread by John Williams | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.