Print out array

The code does not print out like it shoud. What am I doing wrong? Thank you for help
public class test {
    public static void main(String ... args) {
        String text = "array";
        char[] textArray = text.toCharArray();
        System.out.println("     text >" + text);
        System.out.print("textArray >" + textArray);
}output:
     text >array
textArray >[C@addbf1

Once again this is printing out correctly, to get your desired syntax you could loop through the array e.g
public class test {   
   public static void main(String ... args) {
         String text = "array";
         char[] textArray = text.toCharArray();
         System.out.println("text > " + text);
         System.out.print("textArray > ");
         for(int i = 0;i<textArray.length;i++){
             System.out.print(textArray);
}Calypso                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Print out array to JTextArea

    Hello!
    I having trouble to print out the array to a JTextArea.
    This is an asignment so please do not spoonfeed me with code.
    To test that I have added elements correctly in my array I sat it up to print out in console, wich works fine.
    Please give me a hint on what I need to do in order to make it work. Below you see the code that is important for this part of the program.
    Part of my controller:
    //User press "Show Runners" button
              else if(user_action.equals("Show Runners")) {
                   //Call method in model class
                   model.showRunnersBy_startNR();
                   //Display (I will use this once I print out to JTextArea)
                   //view.setDisplayArea(""+model.showRunnersBy_startNR());
              }//End if statementPart of my model
    //showRunnersBY_startNR
         public void showRunnersBy_startNR() {
              for(int i = 0; i <store.getIndex_runner(); i++) {
                   System.out.println(store.global_runner.getRunners());     //Print out in console for now to see that the input and output is working correctly
    //I should have this as "public String showRunnersBy_startNR()" instead with a return statment, correct?
    //I tryed the above but did only manage to print out my latest input in the JTextArea
    Part of my view// Sets the text displayed on the display area
         public void setDisplayArea(String message){
              display.setText(""+message);

    Hello again!
    I see :)
    part of my model
         //showRunnersBY_startNR
         public void showRunnersBy_startNR() {
              for(int i = 0; i <store.getIndex_runner(); i++) {
                   view.setDisplayArea(store.global_runner.getRunners());     
              }part of my view     // Sets the text displayed on the display area
         public void setDisplayArea(String message){
              display.append(""+message+"\n");
         }SetText() seemed to only print out the last one added to the array, so I I used the "append" instead.
    Thanks for the hint.
    Regards
    Martin                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Array keeps printing out null

    I have an array that continues to print out null but when I trace it exactly after I store it, it stores what I want it to store. "White Bread"
    Here is where the errors at:
    int orderNum = 0;
                   while(orderNum < cartItems)
                        printItems = "<html>" + printItems + "<br>1" + itemNameStrings[orderNum] + "</html>";
                        System.out.println(printItems);//Trace
                        System.out.println(cartItems);//Trace
                        System.out.println(orderNum);//Trace
                        System.out.println(itemNameStrings[orderNum]);//Trace
                        orderNum++;
                   }And here is the whole project:
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.border.*;
    import java.text.*;
    public class AdrianP1 implements ActionListener
         //---------------GLOBAL DECLARING------------------
         DecimalFormat Currency = new DecimalFormat("#0.00 dollars");//Currency
         //Changing Variables (void)
         String printItems = "Items";
         int arraySize = 2;
         String[] itemNameStrings;
         boolean first = true;
         boolean order = false;
         String itemName = "Error";
         double itemCost = 0.00;
         int cartItems = 0;
         //Main Frames
         final JFrame frame = new JFrame("Subway Sandwich Store");
         JFrame mainFrame = new JFrame("Subway Sandwich Store | Welcome");
         JFrame menuFrame = new JFrame("Subway Sandwich Store | Main Menu");
         JFrame instrucFrame = new JFrame("Subway Sandwich Store | Instructions");
         JFrame playFrame = new JFrame("Subway Sandwich Store | Play Game");
         JFrame breadFrame = new JFrame("Subway Sandwich Store | Order Bread");
         JFrame toppingFrame = new JFrame("Subway Sandwich Store | Order Toppings");
         JFrame condimentFrame = new JFrame("Subway Sandwich Store | Order Condiments");
         JFrame confirmFrame = new JFrame("Subway Sandwich Store | Confirm Your Order");
         JFrame cartFrame = new JFrame("Subway Sandwich Store | Your Cart");
         //---Main Buttons---
         final JButton mainMenuButton = new JButton("Main Menu");
         final JButton mainMenuButton1 = new JButton("Main Menu");
         final JButton mainMenuButton2 = new JButton("Main Menu");
         final JButton mainMenuButton3 = new JButton("Main Menu");
         final JButton goBackButton = new JButton("Go back");
         final JButton goBackButton1 = new JButton("Go back");
         final JButton goBackButton2 = new JButton("Go back");
         final JButton goBackButton3 = new JButton("Go back");
         final JButton goBackButton4 = new JButton("Go back");
         final JButton playButton1 = new JButton("Order Now!");
         final JButton playButton2 = new JButton("Order Now!");
         final JButton instrucButton = new JButton("Instructions");
         final JButton exitButton = new JButton("Exit");
         //---Play Buttons---     
         final JButton checkButton = new JButton("Check Out");
         final JButton checkButton1 = new JButton("Check Out");
         final JButton cartButton = new JButton("Cart (" + cartItems + ")");
         final JButton breadButton = new JButton("Bread");
         final JButton toppingsButton = new JButton("Toppings");
         final JButton condimentsButton = new JButton("Condiments");
         //-------Bread------
         double bwCost = 0.50, bwlCost = 0.50, biCost = 0.75, bhCost = 0.50;
         boolean whiteB = false, wholeB = false, italB = false, harvestB = false;
         final JButton whiteBreadButton = new JButton("Order White");
         final JButton wholeBreadButton = new JButton("Order Wheat");
         final JButton italianBreadButton = new JButton("Order Italian");
         final JButton harvestBreadButton = new JButton("Oder Harvest");
         //-----Toppings-----
         JButton orderTopButton = new JButton("Order the Selected Topping");
         JLabel pictureTop;
         JComboBox toppingList;
         //----Condiments----
         final JButton ketchupButton = new JButton("Order Ketchup");
         final JButton mustardButton = new JButton("Order Mustard");
         final JButton relishButton = new JButton("Order Relish");
         //-----Confirm------
         final JLabel confirmTextLabel;
         final JButton acceptButton = new JButton("Accept");
         final JButton declineButton = new JButton("Decline");
         //----Cart Screen---
         final JLabel cartItemLabel = new JLabel("<html><u>Items</u><br>No Items.</html>", JLabel.LEFT);
         final JLabel cartPriceLabel = new JLabel("<html><u>Price</u><br>No Items.</html>");
         //-------------END GLOBAL DECLARING-----------------     
         //ActionPerformed Method
         public void actionPerformed(ActionEvent event)
              if(event.getSource()==mainMenuButton || event.getSource()==mainMenuButton1 || event.getSource()==mainMenuButton2 || event.getSource()==mainMenuButton3)
                   playFrame.setVisible(false);
                   mainFrame.setVisible(false);
                   instrucFrame.setVisible(false);
                   menuFrame.setVisible(true);
              if(event.getSource()==goBackButton || event.getSource()==goBackButton1 || event.getSource()==goBackButton2 || event.getSource()==goBackButton3 || event.getSource()==goBackButton4)
                   cartFrame.setVisible(false);
                   confirmFrame.setVisible(false);
                   condimentFrame.setVisible(false);
                   toppingFrame.setVisible(false);
                   breadFrame.setVisible(false);
                   instrucFrame.setVisible(false);
                   playFrame.setVisible(true);
              if(event.getSource()==instrucButton)
                   menuFrame.setVisible(false);
                   instrucFrame.setVisible(true);
              if(event.getSource()==playButton1 || event.getSource()==playButton2)
                   instrucFrame.setVisible(false);
                   menuFrame.setVisible(false);
                   playFrame.setVisible(true);
              if(event.getSource()==breadButton)
                   playFrame.setVisible(false);
                   menuFrame.setVisible(false);
                   breadFrame.setVisible(true);
              if(event.getSource()==toppingsButton)
                   playFrame.setVisible(false);
                   toppingFrame.setVisible(true);
              if(event.getSource()==condimentsButton)
                   playFrame.setVisible(false);
                   condimentFrame.setVisible(true);
              if(event.getSource()==acceptButton)
                   ++arraySize;
                   itemNameStrings = new String[arraySize];
                   itemNameStrings[cartItems] = itemName;
                   System.out.println(itemNameStrings[cartItems]);
                   cartItems++;
                   cartButton.setText("Cart (" + cartItems + ")");
                   confirmFrame.setVisible(false);
                   playFrame.setVisible(true);
              if(event.getSource()==declineButton)
                   confirmFrame.setVisible(false);
                   playFrame.setVisible(true);
              if(event.getSource()==cartButton)
                   int orderNum = 0;
                   while(orderNum < cartItems)
                        printItems = "<html>" + printItems + "<br>1" + itemNameStrings[orderNum] + "</html>";
                        System.out.println(printItems);//Trace
                        System.out.println(cartItems);//Trace
                        System.out.println(orderNum);//Trace
                        System.out.println(itemNameStrings[orderNum]);//Trace
                        orderNum++;
                   cartItemLabel.setText(printItems);
                   System.out.println(printItems);
                   playFrame.setVisible(false);
                   cartFrame.setVisible(true);
              if(order==true)
                   if(event.getSource()==whiteBreadButton)
                        whiteB = true;
                        itemName = "White Bread";
                        itemCost = bwCost;
                        confirmTextLabel.setText("<html>Would you like to purchase <u>" + itemName + "</u> <br>for a cost of <u>$" + Currency.format(itemCost) + "</u>?</html>");
                        breadFrame.setVisible(false);
                        confirmFrame.setVisible(true);
                   if(event.getSource()==wholeBreadButton)
                        wholeB = true;
                        confirmFrame.setVisible(true);
                   if(event.getSource()==italianBreadButton)
                        italB = true;
                        confirmFrame.setVisible(true);
                   if(event.getSource()==harvestBreadButton)
                        harvestB = true;
                        confirmFrame.setVisible(true);
              if(event.getSource()==exitButton)
                   System.exit(0);
              if(event.getSource()==toppingList)
                   JComboBox cb = (JComboBox)event.getSource();
                 String toppingName = (String)cb.getSelectedItem();
                 updateLabel(toppingName);
         //Main Method   
        public static void main(String[] args) throws Exception
             new AdrianP1();         
        //Constructive and Starting Method
        AdrianP1()
             //--------------------------Action Listeners----------------------------------
             //Creates all action listeners
             mainMenuButton.addActionListener(this);
             mainMenuButton1.addActionListener(this);
             mainMenuButton2.addActionListener(this);
             mainMenuButton3.addActionListener(this);
             goBackButton.addActionListener(this);
             goBackButton1.addActionListener(this);
             goBackButton2.addActionListener(this);
             goBackButton3.addActionListener(this);
             goBackButton4.addActionListener(this);
             exitButton.addActionListener(this);
              instrucButton.addActionListener(this);
              playButton1.addActionListener(this);
              playButton2.addActionListener(this);
              breadButton.addActionListener(this);
              toppingsButton.addActionListener(this);
              condimentsButton.addActionListener(this);
              //Bread buttons
              whiteBreadButton.addActionListener(this);
              //Final buttons
              cartButton.addActionListener(this);
              acceptButton.addActionListener(this);
              declineButton.addActionListener(this);
              //--------------------------Splash Screen----------------------------------
             //Declaring
             order = false;
             final ImageIcon welcomePic = new ImageIcon("welcome.jpg");
             final JPanel sMainPanel = new JPanel(new BorderLayout());
             final JPanel sTopPanel = new JPanel(new BorderLayout());  
             final JPanel sButtonPanel = new JPanel(new FlowLayout ());
             final JLabel sTextLabel = new JLabel("Please click the button below", JLabel.CENTER);     
             final JLabel label = new JLabel("Subway Sandwich Store");
             final JLabel welcomeLPic = new JLabel(welcomePic);
              sTopPanel.add(welcomeLPic , BorderLayout.NORTH);
              sTopPanel.add(sTextLabel);
              sButtonPanel.add(mainMenuButton1);
              sMainPanel.add(sTopPanel , BorderLayout.CENTER);
              sMainPanel.add(sButtonPanel , BorderLayout.SOUTH);
                 mainFrame.setContentPane(sMainPanel);
             mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             mainFrame.pack();
             mainFrame.setVisible(true);
             mainFrame.setSize(350,390);
              //--------------------------Main Menu----------------------------------
              //Declaring
              order = false;
              final ImageIcon mainMenuImage = new ImageIcon("mainMenuImage.jpg");
              final JPanel mMainPanel = new JPanel(new BorderLayout());
              final JPanel mTopPanel = new JPanel(new BorderLayout());
              final JPanel mButtonPanel = new JPanel(new FlowLayout());
              final JLabel imageLabel = new JLabel(mainMenuImage);
              final JLabel textLabel = new JLabel("Please click a button", JLabel.CENTER);
              mTopPanel.add(imageLabel , BorderLayout.NORTH);
              mTopPanel.add(textLabel , BorderLayout.CENTER);
              mButtonPanel.add(playButton1);
              mButtonPanel.add(instrucButton);
              mButtonPanel.add(exitButton);
              mMainPanel.add(mTopPanel, BorderLayout.CENTER);
              mMainPanel.add(mButtonPanel, BorderLayout.SOUTH);
                 menuFrame.setContentPane(mMainPanel);
             menuFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             menuFrame.pack();
             menuFrame.setVisible(false);
             menuFrame.setSize(350,390);
              //--------------------------Instructions----------------------------------
              //Declaring
              order = false;
              final JPanel iTopPanel = new JPanel(new BorderLayout());
              final JPanel iButtonPanel = new JPanel(new FlowLayout());
              final JPanel iMainPanel = new JPanel(new BorderLayout());
              final JLabel iTextLabel = new JLabel("Instructions go HRER!", JLabel.CENTER);
              iTopPanel.add(iTextLabel);
              iButtonPanel.add(mainMenuButton3);
              iButtonPanel.add(playButton2);
              iMainPanel.add(iTopPanel, BorderLayout.CENTER);
              iMainPanel.add(iButtonPanel, BorderLayout.SOUTH);
              iTopPanel.setBorder(BorderFactory.createTitledBorder("Instructions"));
              instrucFrame.setContentPane(iMainPanel);
             instrucFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             instrucFrame.pack();
             instrucFrame.setVisible(false);
             instrucFrame.setSize(350,390);
              //--------------------------Play Game----------------------------------
              //Declaring
              order = false;
              final ImageIcon playImage = new ImageIcon("playGameImage.jpg");
              final JPanel pTopPanel = new JPanel(new BorderLayout());
              final JPanel pInstrucPanel = new JPanel(new FlowLayout());
              final JPanel pButtonPanel = new JPanel(new FlowLayout());
              final JPanel pButton1Panel = new JPanel(new FlowLayout());
              final JPanel pButton2Panel = new JPanel(new FlowLayout());
              final JPanel pMainPanel = new JPanel(new BorderLayout());
              final JLabel pImageLabel = new JLabel(playImage);
              final JLabel pTextLabel = new JLabel("Click below to customize your sandwich; or check out", JLabel.CENTER);
              pTopPanel.add(pButton2Panel, BorderLayout.NORTH);
              pTopPanel.add(pImageLabel, BorderLayout.CENTER);
              pInstrucPanel.add(pTextLabel, BorderLayout.SOUTH);
              pButton1Panel.add(breadButton);
              pButton1Panel.add(toppingsButton);
              pButton1Panel.add(condimentsButton);
              pButton2Panel.add(checkButton);
              pButton2Panel.add(cartButton);
              pButton2Panel.add(mainMenuButton2);
              pButtonPanel.add(pButton1Panel);
              pMainPanel.add(pTopPanel, BorderLayout.NORTH);
              pMainPanel.add(pInstrucPanel, BorderLayout.CENTER);
              pMainPanel.add(pButtonPanel, BorderLayout.SOUTH);
              pInstrucPanel.setBorder(BorderFactory.createTitledBorder("Instructions"));
              playFrame.setContentPane(pMainPanel);
             playFrame.setDefaultCloseOperation(playFrame.EXIT_ON_CLOSE);
             playFrame.pack();
             playFrame.setVisible(false);
             playFrame.setSize(350,390);
              //--------------------------Order Bread----------------------------------
              //Declaring
              order = true;
              final ImageIcon whiteBImage = new ImageIcon("whiteB.jpg");
              final ImageIcon wheatBImage = new ImageIcon("wheatB.jpg");
              final ImageIcon italianBImage = new ImageIcon("italianB.jpg");
              final ImageIcon harvestBImage = new ImageIcon("harvestB.jpg");
              final JPanel bTopPanel = new JPanel(new GridLayout(0,2));
              final JPanel bCenterPanel = new JPanel(new FlowLayout());
              final JPanel bButtonPanel = new JPanel(new FlowLayout());
              final JPanel bMainPanel = new JPanel(new BorderLayout());
              final JLabel whiteBLabel = new JLabel(whiteBImage);
              final JLabel wheatBLabel = new JLabel(wheatBImage);
              final JLabel italianBLabel = new JLabel(italianBImage);
              final JLabel harvestBLabel = new JLabel(harvestBImage);
              final JLabel bInstrucTextLabel = new JLabel("Please click the button below a bread to choose", JLabel.CENTER);
              bTopPanel.add(whiteBLabel);
              bTopPanel.add(wheatBLabel);
              bTopPanel.add(whiteBreadButton);
              bTopPanel.add(wholeBreadButton);
              bTopPanel.add(italianBLabel);
              bTopPanel.add(harvestBLabel);
              bTopPanel.add(italianBreadButton);
              bTopPanel.add(harvestBreadButton);
              bCenterPanel.add(bInstrucTextLabel);
              bButtonPanel.add(goBackButton1);
              bMainPanel.add(bTopPanel, BorderLayout.NORTH);
              bMainPanel.add(bCenterPanel, BorderLayout.CENTER);
              bMainPanel.add(bButtonPanel, BorderLayout.SOUTH);
              bTopPanel.setPreferredSize(new Dimension(200, 270));
              bTopPanel.setMinimumSize(new Dimension(200,270));
              bTopPanel.setMaximumSize(new Dimension(200,270));
              bCenterPanel.setBorder(BorderFactory.createTitledBorder("Instructions"));
              breadFrame.setContentPane(bMainPanel);
             breadFrame.setDefaultCloseOperation(breadFrame.EXIT_ON_CLOSE);
             breadFrame.pack();
             breadFrame.setVisible(false);
             breadFrame.setSize(350,390);
             //--------------------------Order Toppings----------------------------------
              //Declaring
              order = true;
              final JPanel tTopPanel = new JPanel(new FlowLayout());
              final JPanel tCenterPanel = new JPanel(new FlowLayout());
              final JPanel tActionPanel = new JPanel(new BorderLayout());
              final JPanel tButtonPanel = new JPanel(new FlowLayout());
              final JPanel tMainPanel = new JPanel(new BorderLayout());
              final JLabel tInstrucTextLabel = new JLabel("<html>Please select a topping from the drop down list above<br> and then click order</html>");
              //Creates list of toppings - file paths must match name
              String[] toppingStrings = { "Olives", "Tomatoes", "Lettuce", "Turkey", "Ham", "Select a Topping"};
              pictureTop = new JLabel();
              //Selects item at index 5
              toppingList = new JComboBox(toppingStrings);
              toppingList.setSelectedIndex(5);
              tActionPanel.add(toppingList , BorderLayout.NORTH);
              tActionPanel.add(pictureTop , BorderLayout.CENTER);
              tActionPanel.add(orderTopButton , BorderLayout.SOUTH);
              tCenterPanel.add(tInstrucTextLabel);
              tButtonPanel.add(goBackButton2);
              tMainPanel.add(tActionPanel , BorderLayout.NORTH);
              tMainPanel.add(tCenterPanel , BorderLayout.CENTER);
              tMainPanel.add(tButtonPanel , BorderLayout.SOUTH);
              //Must go in this method, do not put in main
              toppingList.addActionListener(this);
            pictureTop.setFont(pictureTop.getFont().deriveFont(Font.ITALIC));
            pictureTop.setHorizontalAlignment(JLabel.CENTER);
            updateLabel(toppingStrings[toppingList.getSelectedIndex()]);
            pictureTop.setBorder(BorderFactory.createEmptyBorder(10,0,0,0));
            //Preferred size - widest image and the height of the tallest image
            pictureTop.setPreferredSize(new Dimension(177, 132));
            tCenterPanel.setBorder(BorderFactory.createTitledBorder("Instructions"));
              toppingFrame.setContentPane(tMainPanel);
             toppingFrame.setDefaultCloseOperation(toppingFrame.EXIT_ON_CLOSE);
             toppingFrame.pack();
             toppingFrame.setVisible(false);
             toppingFrame.setSize(350,390);
              //--------------------------Order Condiments----------------------------------
              //Declaring
              order = true;
              final ImageIcon condimentsImage = new ImageIcon("condiments.gif");
              final JPanel cTopPanel = new JPanel(new FlowLayout());
              final JPanel cCenterPanel = new JPanel(new FlowLayout());
              final JPanel cButtonPanel = new JPanel(new BorderLayout());
              final JPanel cMainPanel = new JPanel(new BorderLayout());
              final JLabel cInstrucTextLabel = new JLabel("<html>Please select a button below to order a Condiment</html>", JLabel.CENTER);
              final JLabel condimentsLabel = new JLabel(condimentsImage);
              cTopPanel.add(goBackButton3);
              cTopPanel.add(condimentsLabel);
              cCenterPanel.add(cInstrucTextLabel);
              cButtonPanel.add(mustardButton , BorderLayout.WEST);
              cButtonPanel.add(ketchupButton , BorderLayout.CENTER);
              cButtonPanel.add(relishButton , BorderLayout.EAST);
              cMainPanel.add(cTopPanel , BorderLayout.NORTH);
              cMainPanel.add(cCenterPanel , BorderLayout.CENTER);
              cMainPanel.add(cButtonPanel , BorderLayout.SOUTH);
              cCenterPanel.setBorder(BorderFactory.createTitledBorder("Instructions"));          
              condimentFrame.setContentPane(cMainPanel);
             condimentFrame.setDefaultCloseOperation(condimentFrame.EXIT_ON_CLOSE);
             condimentFrame.pack();
             condimentFrame.setVisible(false);
             condimentFrame.setSize(350,390);                    
              //--------------------------Confirmation Screen----------------------------------
              final JPanel coMainPanel = new JPanel(new BorderLayout());
              confirmTextLabel = new JLabel("<html>Would you like to purchase <u>" + itemName + "</u> <br>for a cost of <u>$" + Currency.format(itemCost) + "</u>?</html>", JLabel.CENTER);
              final JPanel coTopPanel = new JPanel(new FlowLayout());
              final JPanel coButtonPanel = new JPanel(new FlowLayout());
              final JPanel coCenterPanel = new JPanel(new FlowLayout());
              coTopPanel.add(goBackButton);
              coCenterPanel.add(confirmTextLabel);
              coButtonPanel.add(acceptButton);
              coButtonPanel.add(declineButton);
              coMainPanel.add(coTopPanel , BorderLayout.NORTH);
              coMainPanel.add(coCenterPanel , BorderLayout.CENTER);
              coMainPanel.add(coButtonPanel , BorderLayout.SOUTH);          
              coCenterPanel.setBorder(BorderFactory.createTitledBorder("Correct?"));     
              confirmFrame.setContentPane(coMainPanel);
             confirmFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             confirmFrame.pack();
             confirmFrame.setVisible(false);
             confirmFrame.setSize(350,390);
             //------------------------------Cart Screen----------------------------------
              final JPanel caMainPanel = new JPanel(new BorderLayout());
              final JPanel cartRPanel = new JPanel(new BorderLayout());
              final JPanel caButtonPanel = new JPanel(new FlowLayout());
              final JPanel caCenterPanel = new JPanel(new FlowLayout());
              caCenterPanel.add(cartRPanel);
              cartRPanel.add(cartItemLabel , BorderLayout.WEST);
              cartRPanel.add(cartPriceLabel , BorderLayout.EAST);
              caButtonPanel.add(goBackButton4);
              caButtonPanel.add(checkButton1);
              caMainPanel.add(caCenterPanel , BorderLayout.CENTER);
              caMainPanel.add(caButtonPanel , BorderLayout.SOUTH);          
              //cartItemLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
              //cartItemLabel.setHorizontalTextPosition(SwingConstants.LEFT);
              caCenterPanel.setBorder(BorderFactory.createTitledBorder("Your Items"));     
              cartFrame.setContentPane(caMainPanel);
             cartFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             cartFrame.pack();
             cartFrame.setVisible(false);
             cartFrame.setSize(350,390);     
             //--------------------------End of Constructive Method---------------------------
         //Updates the label when combo box is changed
         protected void updateLabel(String name)
            ImageIcon icon = createImageIcon("images/" + name + ".jpg");
            //Sets the image of the icon
            pictureTop.setIcon(icon);
            if (icon != null)
                pictureTop.setText(null);
            else
                pictureTop.setText("Image not found");
        //Returns an ImageIcon, or null if the path was invalid to the icon
        protected static ImageIcon createImageIcon(String path)
            java.net.URL imgURL = AdrianP1.class.getResource(path);
            if (imgURL != null)
                return new ImageIcon(imgURL);
            else
                 //Prints out if file is not found in system window
                System.out.println("Couldn't find file: " + path);
                return null;
         public void updateConfirm()
              //------------------NOT IN USE-------------------
              if(whiteB==true)
                   itemName = "White Bread";
                   itemCost = bwCost;
              if(wholeB==true)
              if(italB==true)
              if(harvestB==true)
              //------------------NOT IN USE-------------------
         public void receiptPrint ()
              //------------------NOT IN USE-------------------
              final JLabel receiptLabel = new JLabel("<html>Your PST:<br>Your GST:<br>Your Total:</html>");
              final JPanel receiptPanel = new JPanel(new FlowLayout());
              receiptPanel.add(receiptLabel);
              receiptLabel.setFont(new Font("Serif", Font.PLAIN, 15));
              receiptPanel.setBorder(BorderFactory.createTitledBorder("Your Receipt"));
              //------------------NOT IN USE-------------------
    }

    I'm certainly not going to read all of that, perhaps someone else here will.You really think so? I seriously doubt it.
    @OP: Please go through these links:
    [How to ask questions the smart way|http://catb.org/~esr/faqs/smart-questions.html]
    SSCCE
    db

  • Print out Forte Arrays

    Greetings All:
    I'd like to know if anyone has had any experience printing out
    Forte Arrays[screen tables] from the Forte Window it exists in.
    Example:
    A Forte window exists that contains Forte Arrays. I
    want an option to either select from the pulldown
    FILE menu or select a button which will automatically
    print out the contents of that Forte Array.
    Has anyone tried to resolve this kind of problem before?
    Regards,
    Antonio Mercado

    try this
    import java.io.*;
    import java.util.*;
    public class PrintE {
    public static void main (String [] args) {
    String line = null;
    String fname = null;
    Vector v=new Vector();
    try {
    System.out.println("Enter file for Entropy print out:");
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    fname = in.readLine();
    catch(IOException e){
    e.printStackTrace();
    try{
    String in= null;
    FileReader fr = new FileReader(fname);
    BufferedReader br = new BufferedReader(fr);
    while ((in = br.readLine()) !=null) {
    v.addElement(in);
    System.out.println(in); }
    catch(IOException e){
    e.printStackTrace();
    System.out.print("Enter line:");
    int index = Integer.parseInt(fname);
    System.out.println(.get(index -1)); //probs here
    assuming user enter say 4
    say
    index=4;
    then
    System.out.println(v.elementAt(index-1));
    hope this helps

  • Help!!! How do I print out a 2d Array?

    Say, I have
    static int[][] board = { {p,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r},
    {n,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r},
    {n,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r},
    {n,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r},
    {n,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r},
    {n,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r},
    {n,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r},
    {n,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r},
    {n,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r},
    {n,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r},
    {n,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r},
    {n,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r},
    {n,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r},
    {n,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r,r} };
    where,
    private static int w = 0; //Block
    private static int f = 1; //Movable Block
    private static int c = 2; //bomb
    private static int n = 3; //nothing
    private static int p = 4;
    private static int r =(int) Math.random()%4;
    How do I print out this 2 d array so it looks like
    Where all these stars are numbers...

    for (int i = 0; i < board.length; i ++)
    for (int j = 0; j < board.length; j ++)
    System.out.print (((j == 0) ? "" : ", ") + board[i][j]);
    System.out.println ();
    I think your random generator is not quite correct as the seed will always be the same causing you to have same random number. try to work that out...

  • How to print an array out a while loop?

    Hi all,
    I'm very new with Labview (6h of Practice) and I meet a problem.
    I create a while loop in which a read the first characters of each line of three files and put it in an 2D array (3 rows and 50 lines).
    My goal is to print this array on the VI's panel in a Table or in a Multicolon Listbox. How to do this? In the While loop or out?
    I use Labview 6i.
    Thanks for your help

    Hi,
    I don't see any problems. I suppose that you can get a 2D array of strings from files.
    Now there are three solutions.
    1. Use of Arrays.
    Right-click on the wire with your 2D array and select "Create->Indicator" from pop-up menu. Now you have a 2D array on the front panel which will show you your data.
    2. Use of Tables.
    Select table control from "Controls->List&Tables". Paste it on the front panel of your vi. Right-click on it and select "Change to indicator" from pop-up menu. Then wire this indicato to your 2D array in the block diagram.
    3. Use of Multicolumn listboxes.
    Paste the multicolumn listbox to the front panel. On the block diagram right-click on it and select "Create->Property node" from pop-up menu. The property node of your control will appea
    r in the diagram. Right-click on it and change property to "Item Names" By selectring "Properties->Item Names" from pop-up menu. Now Right-click on the property node once again and select "Change to write" or "Change all to write" to toggle your property into write mode. Then wire your 2D array to this property node.
    The example is attached.
    Good luck.
    Oleg Chutko.
    Attachments:
    Tables.vi ‏26 KB

  • How to print out the position of 2 dimension arrays?

    there are 2 dimension arrays, how can print out the position of value than 4?
    for example
    0 2 3 2 2 2
    0 1 1 2 5 3
    1 2 3 3 2 1
    print out:
    The pos is ( 5,2).

    Hello
    If I understand your question correctly, you are trying to print out the indexes where the value in your matrix is greater than 4
    If this is the case, then what you need to use is nested for loops e.g.
    for (int i = 0; i< array[0].length; i++)
    for (int j = 0; j< array[].length; j++)
    int value = array[i][j];
    if (value > 4)
    System.out.println("The pos is (" + i + "," + j + ")" );
    Regarding the syntax I have used to get the size of the array, I am not sure if this is correct, but you should have an idea of what I am doing.
    Sajid

  • How can I print out an Array List in my GUI program?

    I have an ArrayList of Objects which I want to print out in a TextArea in my GUI. I tried using setText(), but it seems like that can only handle strings. Does anyone know of an alternative method or some other way to get around this?

    Ok, I have an object name Instrument which contains a double price, String name, int numberInStock. In my GUIFrame class which creates the GUI obviously, I have a button listener that should print out my ArrayList in a TextArea when clicked on a button.
    Here is the code:
    private class showIResponse implements ActionListener{
              public void actionPerformed(ActionEvent e){
                   showText.setText(parseString(ali));
    it is still giving me an error saying "cannot find symbol method parseString(java.util.ArrayList<java.lang.Object>)"

  • How t print out selected values from a Jlist

    hi iam trying to get the selected values from a list to print out as a string but iam getting ,Invalid cast from java.lang.Object[] to java.lang.String.is there any way to get the selected values t print ut as a string?? import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MultipleSelection2 extends JFrame {
    private JList colorList, copyList;
    private JButton copy;
    private String colorNames[] =
    { "Black", "Blue", "Cyan", "Dark Gray", "Gray",
    "Green", "Light Gray", "Magenta", "Orange", "Pink",
    "Red", "White", "Yellow" };
    public MultipleSelection2()
    super( "Multiple Selection Lists" );
    Container c = getContentPane();
    c.setLayout( new FlowLayout() );
    colorList = new JList( colorNames );
    colorList.setVisibleRowCount( 5 );
    colorList.setFixedCellHeight( 15 );
    colorList.setSelectionMode(
    ListSelectionModel.MULTIPLE_INTERVAL_SELECTION );
    c.add( new JScrollPane( colorList ) );
    // create copy button
    copy = new JButton( "Copy >>>" );
    copy.addActionListener(
    new ActionListener() {
    public void actionPerformed( ActionEvent e )
    // place selected values in copyList
    copyList.setListData(
    colorList.getSelectedValues());
    String s1 =(String)colorList.getSelectedValues();

    Since the JList method 'getSelectedValues' returns an object array you'll need to iterate through the array and cast each object in the array to a string as you access them.
    Object[] o = colorList.getSelectedValues();
    for(int count=0,end=o.length; count<end; count++) {
    String s = (String) o[count];
    Hope that helps
    Talden

  • Having trouble printing an array of prime numbers that has been resized

    HI, im having trouble with my printPrimeNumbers() method printing the current state of an array, I can only get it to print the original state it was in. The array is inside of a primeNumbers object. I used checkAndResize to resize that array. my printPrimeNumbers method must be void without a parameter. How could i get my PrintPrimeNumbers method to print out a resized array without modifying the parameter? Any ideas.
    Here is my PrimeNumbers class:
    * Created by IntelliJ IDEA.
    * User: Kevin
    * Date: Mar 4, 2007
    * Time: 1:53:56 AM
    * To change this template use File | Settings | File Templates.
    package primes;
    public class PrimeNumbers {
        private boolean [] sieve;
        public PrimeNumbers(int  upper) {
            initializeSieve(upper);
        public int getNthPrime (int n){
        int prime = 0;
        double num;
        if (n >= sieve.length)
            checkAndResize(n + 1);
        for (int i = 0; i < sieve.length; i++){
            if(sieve)
    prime++;
    if (prime == n)
    return i;
    if (prime < n && i == sieve.length -1)
    checkAndResize(2*sieve.length);
    return -1;
    public int getNumberPrimeNumbers(int n){
    int primes = 0;
    for (int i =0 ; i < sieve.length ; i ++){
    if (n > sieve.length){
    checkAndResize(n);
    if(sieve[i])
    primes++;
    else if (sieve[i])
    primes++;
    return primes;
    public int getSieveSize ()
    return sieve.length;
    public boolean isPrime (int n) {
    if (n > sieve.length){
    checkAndResize(n);
    //initializeSieve(n);
    return sieve[n];
    // prints out the prime numbers inside sieve
    public void printPrimeNumbers() {
    int n = 0;
    boolean first = true;
    System.out.print("[");
    for(int i = 0; i < sieve.length - 1; i++){
    n++;
    if(sieve[i] == true && n != sieve.length - 1) {
    if(first) first = false;
    else System.out.print(" ");
    System.out.print(i);
    System.out.println("]");
    // checks length of sieve with N and then resizes sieve if nessecary.
    private void checkAndResize (int n){
    if ((n + 1) >= sieve.length){
    initializeSieve(2*n);
    private void setMultiples (int k) {
    for (int i = 2*k; i < sieve.length; i += k)
    sieve [i] = false;
    private void initializeSieve (int upper){
    if ( upper < 2)
    sieve = new boolean [2];
    else
    sieve = new boolean [upper + 1];
    sieve[0] = false;
    sieve[1] = false;
    for (int i =2 ; i< sieve.length; i ++ )
    sieve[i] = true;
    int bound = (int) Math.ceil(Math.sqrt(sieve.length));
    for (int i = 2 ; i < bound ; i ++)
    if (sieve[i])
    setMultiples (i);
    private String booleanToString (boolean value)
    if (value)
    return "T";
    else
    return "F";
    public String toString (){
    StringBuffer buf = new StringBuffer("[");
    for (int i = 0; i < sieve.length -1 ; i ++)
    buf.append(booleanToString (sieve[i]) + " " );
    buf.append(booleanToString (sieve[sieve.length -1]) + "]");
    return buf.toString();
    here is the client code
            PrimeNumbers test = new PrimeNumbers(16);
            System.out.println(test);
            System.out.println("There are " + test.getNumberPrimeNumbers(16) +
                    " prime nummbers in the sieve from 1 to 15. \n");
            System.out.println("There are " + test.getNumberPrimeNumbers(26) +
                    "  prime numbers in the resized sieve from 1 to 25.");
            System.out.println("\nThe first 25 prime numbers are:");// makes sense why it doesnt work
            test.printPrimeNumbers();
            System.out.println("\nThe 13th prime number is: " + test.getNthPrime(13));
            System.out.println();
            System.out.println("The number 3001 is prime:  " + test.isPrime(3001));do you see how my methods resized it?
    here is the output:
    [F F T T F T F T F F F T F T F F F]
    There are 6 prime nummbers in the sieve from 1 to 15.
    There are 15 prime numbers in the resized sieve from 1 to 25.
    The first 25 prime numbers are:
    [2 3 5 7 11 13 17 19 23 29 31 37 41 43 47]// this is only the first 15 elements
    The 13th prime number is: 41
    The number 3001 is prime: true
    thanks for taking your time to look at this

    What's the problem?
    You say that there are 15 prime numbers in the range 1-25. Your method printPrimeNumbers() prints the last calculated primes, and that is 15. So the program works.

  • Printing out results in case of object-relational table (Oracle)

    I have made a table with this structure:
    CREATE OR REPLACE TYPE Boat AS OBJECT(
    Name varchar2(30),
    Ident number,
    CREATE OR REPLACE TYPE Type_boats AS TABLE OF Boat;
    CREATE TABLE HOUSE(
    Name varchar2(40),
    MB Type_boats)
    NESTED TABLE MB store as P_Boat;
    INSERT INTO House VALUES ('Name',Type_boats(Boat('Boat1', 1)));
    I am using java to print out all the results by calling a procedure.
    CREATE OR REPLACE package House_boats
    PROCEDURE add(everything works here)
    PROCEDURE results_view;
    END House_boats;
    CREATE OR REPLACE Package.body House_boats AS
    PROCEDURE add(everything works here) AS LANGUAGE JAVA
    Name House_boats.add(...)
    PROCEDURE results_view AS LANGUAGE JAVA
    Name House_boats.resuts_view();
    END House_boats;
    However, I am not able to get Results.view working in case of object-relation table. This is how I do it in the situation of relational table.
    CALL House_boats.results_view();
    House_boats.java file which is loaded using LOADJAVA:
    import java.sql.*;
    import java io.*;
    public class House_boats {
    public static void results_view ()
       throws SQLException
       { String sql =
       "SELECT * from House";
       try { Connection conn = DriverManager.getConnection
    ("jdbc:default:connection:");
       PreparedStatement pstmt = conn.prepareStatement(sql);
       ResultSet rset = pstmt.executeQuery();
      printResults(rset);
      rset.close();
      pstmt.close();
       catch (SQLException e) {System.err.println(e.getMessage());
    static void printResults (ResultSet rset)
       throws SQLException { String buffer = "";
       try { ResultSetMetaData meta = rset.getMetaData();
       int cols = meta.getColumnCount(), rows = 0;
       for (int i = 1; i <= cols; i++)
       int size = meta.getPrecision(i);
       String label = meta.getColumnLabel(i);
       if (label.length() > size) size = label.length();
       while (label.length() < size) label += " ";
      buffer = buffer + label + " "; }
      buffer = buffer + "\n";
       while (rset.next()) {
      rows++;
       for (int i = 1; i <= cols; i++) {
       int size = meta.getPrecision(i);
       String label = meta.getColumnLabel(i);
       String value = rset.getString(i);
       if (label.length() > size) size = label.length();
       while (value.length() < size) value += " ";
      buffer = buffer + value + " ";  }
      buffer = buffer + "\n";   }
       if (rows == 0) buffer = "No data found!\n";
       System.out.println(buffer); }
       catch (SQLException e) {System.err.println(e.getMessage());}  }
    How do I print out the results correctly in my case of situation?
    Thank you in advance

    I have made a table with this structure:
    I am using java to print out all the results by calling a procedure.
    However, I am not able to get Results.view working in case of object-relation table. This is how I do it in the situation of relational table.
    How do I print out the results correctly in my case of situation?
    There are several things wrong with your code and methodology
    1. The code you posted won't even compile because there are several syntax issues.
    2. You are trying to use/test Java in the database BEFORE you get the code working outside the DB
    3. Your code is not using collections in JDBC properly
    I suggest that you use a different, proven approach to developing Java code for use in the DB
    1. Use SIMPLE examples and then build on them. In this case that means don't add collections to the example until ALL other aspects of the app work properly.
    2. Create and test the Java code OUTSIDE of the database. It is MUCH easier to work outside the database and there are many more tools to help you (e.g. NetBeans, debuggers, DBMS_OUTPUT windows, etc). Trying to debug Java code after you have already loaded it into the DB is too difficult. I'm not aware of anyone, even at the expert level, that develops that way.
    3. When using complex functionality like collections first read the Oracle documentation (JDBC Developer Guide and Java Developer's Guide). Those docs have examples that are known to work.
    http://docs.oracle.com/cd/B28359_01/java.111/b31225/chfive.htm
    http://docs.oracle.com/cd/E11882_01/java.112/e16548/oraarr.htm#sthref583
    The main issue with your example is #3 above; you are not using collections properly:
    String value = rset.getString(i);
    A collection is NOT a string so why would you expect that to work for a nested table?
    A collection needs to be treated like a collection. You can even treat the collection as a separate result set. Create your code outside the database and use the debugger in NetBeans (or other) on this replacement code for your 'printResults' method:
    static void printResults (ResultSet rset) throws SQLException {
        try {
           ResultSetMetaData meta = rset.getMetaData();
           while (rset.next()) {
               ResultSet rs = rset.getArray(2).getResultSet();
               rs.next();
               String ndx = rs.getString(1);
               Struct struct = (Struct) rs.getObject(2);
               System.out.println(struct.getSQLTypeName());
               Object [] oa = struct.getAttributes();
               for (int j = 0; j < oa.length; j++) {
                  System.out.println(oa[j]);
        } catch  (SQLException e) {
           System.err.println(e.getMessage());
    That code ONLY deals with column 2 which is the nested table. It gets that collection as a new resultset ('rs'). Then it gets the contents of that nested table as an array of objects and prints out the attributes of those objects so you can see them.
    Step through the above code in a debugger so you can SEE what is happening. NetBeans also lets you enter expressions such as 'rs' in an evaluation window so you can dynamically try the different methods to see what they do for you.
    Until you get you code working outside the database don't even bother trying to load it into the DB and create a Java stored procedure.
    Since your current issue has nothing to do with this forum I suggest that you mark this thread ANSWERED and repost it in the JDBC forum if you need further help with this issue.
    https://forums.oracle.com/community/developer/english/java/database_connectivity
    When you repost you can include a link to this current thread if you want. Once your Java code is actually working then try the Java Stored procedure examples in the Java Developer's Guide doc linked above.
    At the point you have any issues that relate to Java stored procedures then you should post them in the SQL and PL/SQL forum
    https://forums.oracle.com/community/developer/english/oracle_database/sql_and_pl_sql

  • Print specific array index

    How do i print out a specific slot of the array created from the following function? I can print them all by putting the dynamic counter varible in the index parameter but if i put a number instead of the dynamic "counter" variable in the index parmeter then the io exception is thrown. this function gets called every time a node in an XML document is encountered. Just printing the same index multiple time would be acceptable as this is just a learning script.
      private void showData (String s)
        throws SAXException
            try {
                arr0[numCt]=s;
                out.write(arr0[0]);
                //out.write (s);
                out.flush ();
                numCt++;
            } catch (IOException e) {
                throw new SAXException ("I/O error", e);
        }

    SAX parsing has nothing to do with your array problem. It should not be in your example.
    Your example is not small.
    It does not compile.
    It uses deprecated methods, and you know it does.
    You shouldn't even be trying to parse an xml document if you can't iterate over and access data from an array properly. There is a link to the tutorials at the top of the New To Java forums.
    Also, from your previous post you don't even know the syntax of this language. You can't just toss a bunch of code into a text document and hope to get something useful.
    Also, do not berate people trying to help you and do not demand answers. Your lack of understanding is your own fault not ours. You would be wise to reread posts you don't comprehend, or purchase learning materials to fill the gaps in your knowledge.
    Here is a working example with arrays throwing out all the XML garbage that shouldn't even be in your example.
    There are two examples: One example uses your swiss army knife method. And the other "better" example uses discrete methods that perform individual functions denoted by their names.
    If you continue to be an ass to this forums contributors don't expect answers.
    import sun.plugin.dom.exception.InvalidStateException;
    public class BooksLibrary {
        private int numCt = 0;
        private String[] arr0 = new String[100];
        public static void main(String argv[]) {
            System.out.println("Tour way: \n");
            yourWay();
            System.out.println("\n\nReasonable way: \n");
            reasonableWay();
        private static void yourWay() {
            BooksLibrary bl = new BooksLibrary();
            bl.fillArray();
        private void fillArray() {
            for(int i=0; i < arr0.length; i++) {
                showData("" + i);
            System.out.println();
            Is this method showing data? yes
            Should this method also add data to the array? no
            Should this method only show the data in index zero and not the data in the index that was just assigned? no
            What is the purpose of this method?
        private void showData(String s) {
            arr0[numCt] = s;
            System.out.print(arr0[0] + " ");
            numCt++;
        private static void reasonableWay() {
            BooksLibrary bl = new BooksLibrary();
            try {
                bl.showLastAddedData();
            } catch (Exception e) {
                System.out.println("No Data Added");
            try {
                bl.showAllAddedData();
            } catch (Exception e) {
                System.out.println("No Data Added");
            for(int i=0; i<5; i++) {
                bl.addData("" + i);
            try {
                bl.showLastAddedData();
            } catch (Exception e) {
                System.out.println("No Data Added");
            try {
                bl.showAllAddedData();
            } catch (Exception e) {
                System.out.println("No Data Added");
            //try to add too much data
            try {
                for(int i=0; i < 1000; i++) {
                    bl.addData("" + i);
            } catch (Exception e) {
                e.printStackTrace(System.out);
        private void addData(String s) {
            arr0[numCt++] = s;
        private void showLastAddedData() {
            if(numCt <= 0) {
                throw new InvalidStateException("No data has been added to array yet");
            System.out.println(arr0[numCt - 1]);
        private void showAllAddedData() {
            if(numCt <= 0) {
                throw new InvalidStateException("No data has been added to array yet");
            for(int i = 0; i < numCt; i++) {
                System.out.print(arr0[i] + " ");
            System.out.println();
    }

  • Print out some numbers

    Hello:
    At the movement I got array nums[]={"1", "2", "3", "4", "5", "6", "7", "8"},
    Please tell me how to print out some numbers from the array by using for loop, and the result exactly like System.out.println( " 1 2 3 4 "); System.out.println(" 5 6 7 8);
    Please run my codeing first, I'd like the result exactly same as my coding showing.
    Thanks
    import java.awt.*;
    public class Test{
    private static Test t;
    private static String nums[]={"1", "2", "3", "4", "5", "6", "7","8"};
    public static void main(String [] args){
         t=new Test();
    private Test(){
         print();
    private void print(){
         System.out.println(" 1 2 3 4 ");
         System.out.println(" 5 6 7 8 ");
    }

    Ugh!
    I didn't see that you wanted 1,2,3,4 and 5,6,7,8 on new lines. This will do the trick. It's ugly but it works.
    public class Test
        private static Test t;
        private static String nums[] = {"1", "2", "3", "4", "5", "6", "7", "8"};
        public static void main( String[] args )
            new Test();
        private Test()
            print();
        private void print()
            for (int i = 0; i < nums.length; i++) {
                if (i == 4) {
                    // Print a Blank Line
                    System.out.println("");
                String num = nums;
    System.out.print(num + " ");
    cheers,
    Greg

  • Printing out a diamond shape

    I am in an intro Java course and the instructor asked us to write a program that prints out a diamond shape using the * symbol.
    I have been racking my brain for hours and I cannot figure it out.
    We must use the Scanner class.
    Also, we only have been taught the:
    if
    if else if
    while
    do while
    for
    printf
    and a very basic array
    PLEASE HELP...THIS IS DUE THURSDAY!!!!

    I am in an intro Java course and the instructor asked
    us to write a program that prints out a diamond shape
    using the * symbol.Okay.
    So, ignore Java for the moment.
    Break the problem down into pieces. I have to assume that you must have some idea on how to do some of it. If not, speak to your instructor.
    How would you tell somebody to do it if you had to write down the directions, and that person was going to write it with pencil & paper?
    That person doesn't know what a diamond is, and he will do exactly what you tell him, but you must make your instructions simple and precise. You can tell him in English, pseudocode, or a combination--whatever is easiest for you.
    Do this first. If you can't do this, then you can't write it in Java.
    Once you do that, work on translating those steps to Java.
    I have been racking my brain for hours and I cannot
    figure it out.What, precisely can't you figure out? There are several steps here (as you'll see when you do the above exercise). Which of them are giving you trouble? If you can't even write the steps, or can't translate any of them, then you need to speak to your instructor, or engage the services of a private tutor.
    >
    We must use the Scanner class.Okay.
    Do you know how to use that class? Can you think of a step in your program where it might be useful?
    Also, we only have been taught the:
    if
    if else if
    while
    do while
    for
    printf
    and a very basic arrayYou don't need more than that. (Assuming you also know how to define classes, methods, and variables. You can't do anything in Java without that.)
    PLEASE HELP...THIS IS DUE THURSDAY!!!!Okay. But nobody who's going to help you here cares about your deadline. Managing your time is entirely your issue. We'll help you with the technical stuff, on our own scheule.

  • Printing out to a gui

    Hi,
    Can someone give me a hand with this??
    for (int b = 0; b < a.length; b++)
              ta = new JTextArea(a);
    this is going through my array of names and I want them to print out but when I run the program it keeps over writing the line and I end up with just the last name on the screen. Any ideas??
    Thanks
    DeeSheehan

    Dude, come up with some more descriptive variable names, at least call the array names or something, not b
    In every pass of the loop you create a new JTextArea and assign it to ta, thus overwriting what was there before. Of course you only end up with the last one after the loop.

Maybe you are looking for

  • Single-user mode: How to mount and access an external USB drive?

    My MacBook Pro HD is acting up. Cannot boot normally or into "safe mode". Cannot reinstall OS without wiping out the HD. Need to recover some critical files but DiskUtil First Aid and Restore options cannot successfully complete. Problem traced down

  • I can't get my iTunes to update to the new version.

    I updated my iPod and so I need to update my iTunes. When I try it tells me this: "Error writing to file: C:\Program Files\Common Files\Apple\Mobile Device Support\SyncServices\Schemas\Calendars.syncschema\Contents\Resources\ja.lproj\L ocalizable.str

  • Display problem

    Product name-15-p001TX Operating systems-Windows 8.1  Respected to whom so ever is concern,      In my notebook pc i have an display problem, some times while working on it, it blinks automatically. sometimes it is bright and some times it is lite. T

  • How i can check my phone is under warrenty???????

    i want to know, how i can check my phone warrenty period and my phone originallty...........

  • Unable to view lync history in my outlook folder

    Hi, My chat history can be seen in lync chats but when i click on the button 'View more in outlook' i get error like below. Any tips on how to solve this ? Lync UCMAPI is connected to Outlook, but one or more folders are not updating. OK    Thanks, T