How to Print the Contents of an Array Horizontally

How to print integer arrays horizontally?

It is because you are using System.out.println. It means that it goes to the next line, it works like if you add a line break at the final of the String. Change it for System.out.print to print all your code in a line.

For example, using System.out.println:

Code

System.out.println("Hello");
System.out.println("World");

Output

Hello
World

Now using System.out.print:

Code

System.out.print("Hello");
System.out.print("World");

Output

HelloWorld

Finally using System.out.print and String with \n:

Code

String string = "Hello\nWorld";
System.out.print(string);

Output

Hello
World

Look that using \n and System.out.println have the same behaviour.

Printing an array of list horizontally

Just print the name outside the loop so that it is not repeated:

int[] testScore1 = { 99, 67, 98, 78, 56 };
int[] testScore2 = { 88, 78, 54, 23 };
int[] testScore3 = { 77, 67, 55 };
Console.Write("Morgan: "); // Note the print here
foreach (int i in testScore1)
{
Console.Write(i + " ");
}
Console.WriteLine(); // this adds a new line at the very end so you can print another person's scores on a new line

How to display my values in props array horizontally

Your Print component is wrapped inside div also it seems Avtar component add it's own div so you can simply return Avtar from print, and to parent div use display: flex to align them horizontally.

const PrintHorizontal = props => {
return (
<div className="horizontal">
{ props.values.map(value => {
<Print key={value.id} data={value.x} />
})}
</div>
)
}

const Print = props => {
return (
<Avatar>{props.data}</Avatar> //Avatar is a component imported from materialUI
)
}

In your css file

.horizontal {
display: flex;
align-item: center;
}

How to output arrays horizontally in c++

You can try use a tab to separate your output. Tab is represented by the character '\t'.

for( i = 1; i < 10; i++)
{
inFile >> retrievenum[i];

sum += retrievenum[i];
//Here I'm outputting the array to my output textfile
outFile <<retrievenum[i] << '\t';
}

// outFile << endl;

How to print a 2d array horizontally multiple times

If you want to print 2d array horizontally, you have to repeat printing row n times before next row:

int n = 3; // user input
char[][] board = new char[][] { { 'x', 'x', 'x' }, { '0', '0', '0' } }; //example board

for (int row = 0; row < board.length; row++)
{
for (int i = 0; i < n; i++)
{
for (int col = 0; col < board[row].length; col++)
{
System.out.print(board[row][col]);
}
System.out.print("\t"); //arrays separated by tab
}
System.out.println();
}

Output:

xxx xxx xxx 
000 000 000

I hope this help.

PHP Array output shows only in horizontal

You can use \n to break line. $output.= $roomsCount[$i] . " \n"; Or as @WesleySmith said:
it might be better to use $output.= $roomsCount[$i] . PHP_EOL;, or, if you're looking to output this in a browser, you might want $output.= $roomsCount[$i] . '<br>';



Related Topics



Leave a reply



Submit