Printing Array in columns

Kinda new to Java and I need to know how I could modify my code to print in a specfic format. I am attempting to print 1000 numbers and this sequence style just is to long for any decent screen.
I'd like to make it where the info would print in 5 columns:
array[0] array[1] array[2] array[3] array[4]
array[5] array[6] array[7]......
  public static String printArray(int array[])// prints an array in sequence
    String output = "";
    for (int i = 0; i < array.length; i++)
      output += array[i] + " ";     
  return output;I'm guessing this would be done in some type of loop but I have no clue how to go about it, I've attempted several times and am getting a little flabergasted.

As kajbj said. Here's the complete code...
public static String printArray(int array[])// prints an array in sequence
    StringBuilder output = new StringBuilder();
    for (int i = 0; i < array.length; i++)
      output.append(array);
if( (i+1)%5 == 0)
output.append("\n");
return output.toString();

Similar Messages

  • How to Print the Report Column headers on each page of any report

    Can someone offer assistance on how I can go about achieving the ability to show and print the Report Column headers on each page of any report using the Print Attributes of APEX 3.0? These reports will be printed using Excel and Word.
    I read a thread with a similar request but the answer seems vague for my level of understanding.
    I am connected to a print server and using BI Publisher.
    Thanks,
    Ric

    Hello Ric,
    >> These reports will be printed using Excel and Word.
    I'm not sure I understand what you are trying to do. You are using a very powerful tool – BI Publisher – why do you need Excel or Word for printing? Is there a special need only Excel or Word can provide?
    One of the major advantages of using BI Publisher is that it's taking care of all these tedious tasks like reasonable page breaking, headers and footers, and also table headers.
    Regards,
    Arie.

  • How to print the row  ,column,and particular cell in separate color

    how to print the row  ,column,and particular cell in separate color IN ALV GRID

    HI,
    Here you go good program links
    <a href="http://www.sapfans.com/forums/viewtopic.php?t=52107">How to Set Color to a Cell in AVL</a>
    <a href="http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm">ALV Grid Coloring</a>
    Thanks
    Mahesh

  • Maximum number of character we can print in a column uing ALV grid display

    Hi frnds,
    My requirment is to print 500 charcter data in a column using ALV grid display.
    Could any body tell me is it possible and the maximum character it can i print in a column using ALV grid dispaly.
    Regards,
    Sandipan

    Hi Sandipan,
    refer notes 857823, 910300 and 959775. All these say there is a limitation of 128 characters.
    857823 - ALV grid: Strings with a maximum of 128 characters
    Symptom
    Entries in cells of the type CHAR or string are truncated after 128
    characters in the SAP GUI.
    also refer,
    ALV Grid Control (cl_gui_alv_grid), function module (Full-screen) Grid
    (Reuse_alv_grid_display, SAPLSLVC_FULLSCREEN), SAPGUI, back end, front end
    Cause and Prerequisites
    The data table that is sent to the front end only allows character values
    with the length 128.
    Solution
    This is the standard system behavior and cannot be changed.

  • Print out a column value only if another column has a specific value (CASE Statement)

    Hello all,
    I tried many hours to find a solution for the following request but wasn't successful. Maybe you could help me.
    I've using the already existing SQL Views in Microsoft Service Manager to do some basic reporting about my tickets.There is no closed date in the activity tickets so I decided to print out the lastmodified timestamp when the status is "closed".
    That's my query:
    SELECT DISTINCT
    dbo.DisplayStringView.DisplayName AS Status,
    CASE WHEN dbo.DisplayStringView.DisplayName = 'Closed' THEN dbo.DisplayStringView.LastModified ELSE 'NO CLOSED Date' END AS ClosedDate
    FROM dbo.MTV_System$WorkItem$Activity$ManualActivity LEFT OUTER JOIN
    dbo.DisplayStringView ON dbo.MTV_System$WorkItem$Activity$ManualActivity.Status_8895EC8D_2CBF_0D9D_E8EC_524DEFA00014 = dbo.DisplayStringView.LTStringId
    Unfortunatelly I'm not getting the value from dbo.DisplayStringView.LastModified. SQL outputs that it is not possible to convert the string to date/time.
    I think there is a problem with the CASE statement in combination with a value select.
    Any ideas how to print out a column value only if another column has a specific value?

    I think it is the other way if you want the missing date shown as a string.
    CASE
    WHEN
    dbo.DisplayStringView.DisplayName
    =
    'Closed'
    THEN
    Convert( varchar(10),dbo.DisplayStringView.LastModified
    , 101) ELSE
    'NO CLOSED Date'
    END
    AS
    ClosedDate 

  • Printing Infinite # of Columns in Append Table to Report

    I am in need of a bit of help here in regards to dealing with the Append Table to Report.vi
    With this VI I can print up to a certain # of columns before the VI starts to wrap columns (& subsequent data under each column) downward in vertical manner.
    I am looking for a way to do the following:
    1) center the text in all columns
    2) set a pre-set # of columns per page, and then print the remaining columns to a separate page thereafter
    3) avoid column header & data from being folded beneath to the subsequent row
    See the attached code and print-outs.
    Thanks!
    Solved!
    Go to Solution.
    Attachments:
    Example Test Report.vi ‏36 KB
    Too many columns!.pdf ‏12 KB

    Using the "Append Table to Report" VI, you can't specify center alignment, through if you enable gridlines, it makes the tables more readable.  If you were to generate an Excel report, you would have more control and be able to specify cell alignment.
    In the Report Generation Toolkit, using Standard Report, there is no way to get or automatically print the page number.  You can do it manually by keeping track of how many pages have been printed if your using the "New Report Page" VI.  
    Using the VI script you posted, I modified it to illustrate how to selectively add columns to the report.  Its usually not standard practice for us to write code for customers, but this example seemed good for the Community Example Page (http://www.ni.com/code/), and with your permission I'd like to post it there as well.
    Product Support Engineer
    National Instruments
    Attachments:
    Example_Test_Report_Done.vi ‏43 KB

  • Print the Discount column in PO Printout

    Hi,
    I want to print the Discount column in PO Printout. Where this field (Discount) shows in PO.
    Regards..

    Dear,
    After Maintain Parameter "X" in front of your conditopn type in Print Parameter coloumn, where Discount Column s
    hows.
    After maintaining above parameter, create PO....
    Now go to ME22N...click on print preview button..
    Now you will see your discount printed in the form.
    Also please tell me the Tables for Discount against material (with line item)..
    Table KOMV
    Regards
    utsav

  • When printing an e-mail, it prints in narrow column - not full page width!

    when printing an e-mail, it prints in narrow column - not full page width!
    Spacing is also erratic

    check the default paper size for your printer on the printers folder in Windows.

  • Summing 2D Array by Columns

    Im trying to sum a 2D array by column
    Say I have 5 rows and 5 columns im trying to get the sum of all the values in the second column.
    What I have so far and have been hassling with for a while is:
    public static float sumCol(int[][] table, int rowsize, int colsize)
          int[] c = new int[colsize];
          float sum=0;
          for (int row=0; row < rowsize; row++)
            for (int col=0; col < colsize; col++)
                c[col] = table [row][col];
                sum = myMethods.sum(c);
          return sum;the sum method calculates the sum of an array
    If you can help me and just give me some pointers on how to get this, 2D arrays I think play tricks on your mind.

    I dont understand why this is giving an out of bounds
    when i call it
    public static float sumCol(int[][] table, int
    rowsize, int colsize)
    int[] c = new int[colsize];
    float sum=0;
    for (int row=0; row < rowsize; row++)
    c[row] = table [row][colsize];
    sum = myMethods.sum(c);
    return sum;
    Because number of columns is not the same as number of rows.
    I still don't understand why you are creating an array. You don't need one.
    Kaj

  • Printing array help please!

    Hi, I have a problem with printing arrays in a certain order. Let me descbribe it, by the way I'm using Java version 1.3 if that helps.
    ok, what I need to do is print out on a single line all the strings found on the command line that end in .java and then I need to print out all the strings found on the command line that end in .class. So say I type on the command line a.java b.class c.java d.class. Then it would print out a.java c.java b.class d.class.
    any help would be appreciated!

    here it goes the complete code:
    * running example: java a.class b.java c.class d.class h.java
    public class Nickal01
         static public void main(String[] args)
              String classes = "";
              for(int i=0; i<args.length; i++)
                   if(args.endsWith(".class"))
                        classes += args[i] + " ";
                   else
                        System.out.print(args[i]+" ");
              System.out.println(classes);

  • Print array to table

    I need to print two arrays in a table, i.e. each array represents another column in the table.
    I currently have this which outputs the results of each array but not in table format:
    String[] FN = (String[])setFN.toArray(new String[setFN.size()]);
                   String[] SerialArray = (String[])setSerial.toArray(new String[setSerial.size()]);
                   StringBuilder FNbuilder = new StringBuilder(FN.length);
                   for (int i=0;i<FN.length;FNbuilder.append(FN[i++])) FNbuilder.append("\n");
                   for (int i=0;i<SerialArray.length;FNbuilder.append(SerialArray[i++])) FNbuilder.append("\n");
                   JOptionPane.showMessageDialog(null, FNbuilder.toString(), "Printing results", JOptionPane.INFORMATION_MESSAGE);I hoped it would be as easy as this, but its not! -
    JTable jTable1 = new JTable (FN);
    String [] columnNames = {"Serial Number", "Friendly Name"};
    Object [][]data = {
         {SerialArray},{FN}
    JTable jTable1 = new JTable (data, columnNames);Any advice would be greatly appreciated.
    Thanks!

    Those sort of parallel arrays are generally a bad idea. I call that code smell "object denial".
    Anyway, you have several options.
    1. Copy the data over to a Object[][] where the data is orgainized by row, not column.
    2. Define an object that holds a serial number and a friendly name, call it Product, or whatever it should be. Instead of having separate arrays have a single:
    List<Product>
    subclass AbstractTableModel to draw its data from a List<Product>. Done!

  • Print labels row*column wise

    Hi Gurus,
    We have a requirement to create a report which will print labels (RTF layout using XML publisher). Our client wants supplier information (labels, single label of 8 lines) to be printed on a single page i.e. on A4 size paper, 3*8 = 24 labels should get printed like- (Below Lxy is a single label with 8 lines, x and y denotes numbers below)
    L01 L02 L03
    L04 L05 L06
    L07 L08 L09
    L10 L11 L12
    L13 L14 L15
    L16 L17 L18
    L19 L20 L21
    L22 L23 L24
    This will be a nightly job and once client will come in the morning all the labels will get printed on the A4 size papers. These number of labels in a single request may vary as well eg- it can be either 4 during one night or 29 during another, so this has to be taken care while printing.
    I can not call it as a matrix report as number of rows and columns may both get changed dynamically.
    Is anybody came across the same requirement? Please provide your valuable inputs.
    Thanks in advance.
    Rgds,
    Sumir

    HI,
    Here you go good program links
    <a href="http://www.sapfans.com/forums/viewtopic.php?t=52107">How to Set Color to a Cell in AVL</a>
    <a href="http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm">ALV Grid Coloring</a>
    Thanks
    Mahesh

  • Lots of blank space when printing array with only last element printed

    I have a slight problem I have been trying to figure it out for days but can't see where my problem is, its probably staring me in the face but just can't seem to see it.
    I am trying to print out my 2 dimensional array outdie my try block. Inside the trying block I have two for loops in for the arrays. Within the second for loop I have a while to put token from Stringtokeniser into my 2 arrays. When I print my arrays in this while bit it prints fine however when I print outside the try block it only print the last element and lots of blank space before the element.
    Below is the code, hope you guys can see the problem. Thank you in advance
       import java.io.*;
       import java.net.*;
       import java.lang.*;
       import java.util.*;
       import javax.swing.*;
       public class javaflights4
          public static final String MESSAGE_SEPERATOR  = "#";
          public static final String MESSAGE_SEPERATOR1  = "*";
          public static void main(String[] args) throws IOException
             String data = null;
             File file;
             BufferedReader reader = null;
             file = new File("datafile.txt");
             String flights[] [];
                   //String flightdata[];
             flights = new String[21][7];
             int x = 0;
                   //flightdata = new String[7];
             int y = 0;
             try
                reader = new BufferedReader(new FileReader(file));   
                //data = reader.readLine();   
                while((data = reader.readLine())!= null)   
                   data.trim();
                   StringTokenizer tokenised = new StringTokenizer(data, MESSAGE_SEPERATOR1);
                   for(x = 0; x<=flights.length; x++)
                      for(y = 0; y<=flights.length; y++)
                         while(tokenised.hasMoreTokens())
                            //System.out.println(tokenised.nextToken());
                            flights [x] [y] = tokenised.nextToken();
                            //System.out.print("*"+ flights [x] [y]+"&");
                   System.out.println();
                catch(ArrayIndexOutOfBoundsException e1)
                   System.out.println("error at " + e1);
                catch(Exception e)
                finally
                   try
                      reader.close();
                      catch(Exception e)
             int i = 0;
             int j = 0;
             System.out.print(flights [j]);
    //System.out.println();

    A number of problems.
    First, I bet you see a lot of "error at" messages, don't you? You create a 21x7 array, then go through the first array up to 21, going through the second one all the way to 21 as well.
    your second for loop should go to flights[x].length, not flights.length. That will eliminate the need for ArrayIndexOutOfBounds checking, which should have been an indication that you were doing something wrong.
    Second, when you get to flights[0][0] (the very first iteration of the inner loop) you are taking every element from the StringTokenizer and setting flights[0][0] to each, thereby overwriting the previous one. There will be nothing in the StringTokenizer left for any of the other (21x7)-1=146 array elements. At the end of all the loops, the very first element in the array (flights[0][0]) should contain the last token in the file.
    At the end, you only print the first element (i=0, j=0, println(flight[ i][j])) which explains why you see the last element from the file.
    I'm assuming you have a file with 21 lines, each of which has 7 items on the line. Here is some pseudo-code to help you out:
    count the lines
    reset the file
    create a 2d array with the first dimension set to the number of lines.
    int i = 0;
    while (read a line) {
      Tokenize the line;
      count the tokens;
      create an array whose size is the number of tokens;
      stuff the tokens into the array;
      set flights[i++] to this array;
    }

  • Address Book Print list view column format

    Is there a way of changing the column width of the List View when printing the contacts in Address Book? I select all contacts, check the boxes for address and notes and send so PDF in Preview. The left hand column (Names) takes nearly half the page width. The center column with all the addresses, e-mails and notes is very narrow, which causes the text to wrap in the middle of the address or e-mail.
    If it can't be changed, does anyone know of an application that will use the address book data and allow me to format pages to my specification?

    Thank you KT. I downloaded the utility and was able to create a tab delimited file from Address Book. I also imported the data into Numbers but I could not produce a report format I wanted. I was afraid I was forced to copy the data into Windows and use one of the many address book formatters.
    I kept searching the web and read about Palm Desktop for Mac but that did not include the Notes field. Last night, I believe I found a reasonable solution, it is called "Address Book Reports" by Scruffy Software. There are choices of format and page size. I will try it out today and if it's OK will send the $15 shareware fee.

  • Export to PDF is not printing all the columns in one single page.

    Hi,
    I have a report, I am exporting the report to PDF, but ALL the columns are not printing in a single page, It is getting printed 2 or more pages.
    I am okay if I have a horizontal scroll bar or if the test size is reduced. Please see the recording and let me know whether it is possible.

    Sorry sir, It is a slip of the tongue, I corrected my response already.
    So it is defenitely possible to make ALL the columns appear in the same page in PDF regardless of how much width the report occupies?
    If yes, can I see a horizontal scroll bar or the text will be shrinked to fit the page?

Maybe you are looking for

  • Photoshop elements 13 as a gift

    Hello everybody, I am new here. Me stepfather offered me the software photoshop element and I have to download it now. I have the licence number, and I created my account Adobe, but I do not see where to download it, I can only buy it. Is it somebody

  • Driver updates for HP PSC Scanner

    I've owned a HP Scanner  (HP PSC 2210) for a few years. Its scanned and copied pretty well. Then it stopped. A message appeared saying a communication problem had occured. This happened repeatedly so.. - Via the print and scan preference I uninstalle

  • Is is possible to run aggregate queries (cf SQL's "group by") on a CQ5 repository?

    I am trying to produce a report of how many images were added to our crx repository (under cq 5.3) in the last year, by the directory to which they were added. In SQL I'd do something like    SELECT COUNT(*) FROM image WHERE image.date >= '2012-01-01

  • Level 2 status question

    recently recieved an email welcoming me to level 2 and it begins with: Please include the line below in follow-up emails for this request. Follow-up: 11111111 (random numbers in place of actual ones in the email) I dont understand what this is..some

  • Help: will iMovie delete the videos from iPhoto when i get the thumbnails?

    i have lots of important videos on iphoto and i am afraid imovie might wipe out all of the videos when it gets the thumbnails. has this ever happened to anyone before?