473,394 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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?
Jul 8 '21 #1
3 4334
dev7060
636 Expert 512MB
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. }
Jul 10 '21 #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
Jul 12 '21 #3
dev7060
636 Expert 512MB
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.
Jul 12 '21 #4

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

Similar topics

3
by: Bill Cohagan | last post by:
I'm writing a console app (in C#) and I want to be able to redirect the standard input/output streams when it's run at a command prompt. IOW I want to support the "<" and ">" redirection syntax....
3
by: qbschmidt | last post by:
i can input and output to a text file as long as the file is in the same directory as my c++ program. but i cant figure out how to input/output to a file in another directory i.e. I:\c++projects...
2
by: qazmlp1209 | last post by:
FAQ at "http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.6" states that the following program will not work properly: --------------- int main() { char name; int age; for (;;)
3
by: ES Kim | last post by:
Hi, I am using VC++ .NET 7.0. I'd like to debug my console program, using redirection of input/output for convenience. Help menu tells me it's possible to specify a file name as a command-line...
4
by: Jerry LeVan | last post by:
Hi, I am adding image and large object support in my Cocoa postgresql browser. Are there going to be any enhanced bytea support functions coming along? It seems sorta silly to have to write...
2
by: Key9 | last post by:
Question about basic input output. HI All I am a new C++er Suppose I am designing a i/o device . system have screens . system have keyboards.
4
by: lenin42001 | last post by:
Can someone be off assistance? We're trying to input/output some patients data in a hypothetical form. The records display sequentially & can be retrieved from a data store................This must...
3
by: John Williams | last post by:
I'm writing a stagenography program to experiment with how it works. The algorithm I'm using appears to be producing the correct result...however I'm struggling with the file input. I never...
18
by: WilhelmAccess | last post by:
Hi, I am trying to automate the running of a SQL Query. I have a Table in Access 2003 that contains records with several fields, (member identifier, $ amount and months during the year they were...
3
by: Rainy | last post by:
Hello! I'm having some trouble with pyserial package, I'm sending commands and reading responses from a custom pcb, and sometimes I get a proper response, at other times I get nothing, and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.