Solving a java question

I had been ask by a question to produce the following output:
however I only know indents such as "/n" and "/t"
I am not able to produce this unless i use the manual methods...is there codes such tat i am able to produce spaces?
Thanks

sorry...there is some problem...the output should
look like a christmas tree
***The forum automatically deletes leading spaces unless you put the text in between code markers.
Basically, you need to write a method that takes as its arguments two ints ... one as the number of asterisks, and one as the total width. Total width can also be an implicit argument, if you know it is always going to be the same.
Then, create a string with the number of asterisks centered in the total width. Subtract the number of asterisks from the total width, and then divide by two. This is the number of leading space characters (' ') you need. You can probably forget the trailing spaces.
Call your method from inside a loop. YOu will probably want to start with one asterisk, and then increment the loop by 2, so you always have an odd number of asterisks.
After the tree portion, call the method a few times with the trunk width.
Done.
The implementation in Java is left to the interested student or OP.

Similar Messages

  • Java Question... please help

    I am running  Snow Leopard  (mac os x version 10.6.8)
    For the past couple of years I've played gin in yahoo games.  
    Yesterday when I entered the gin lobby ...the font was so tiny
    I wasn't able to read it.   I checked Java on my computer and
    it is enabled, however I just realized when I go into the gin
    lobby... there is no java icon on the dock.   Since the font size
    is fine in all other applications, I am presuming this is a Java
    issue.  
    Help if you are able.. please and thanks

    Huh? Is this a Java question? Where's the Java? I just see a little JavaScript. Do you know how to use servlets and JSPs?
    Jesper

  • What kind of Java questions can I ask?

    Here's a change:
    I want to interview some good java people. I have lots of Java questions in mind which I could ask them, however fellow JavaGuru's
    I would like some potential questions from you which I could ask someone who claims he/she is a good java programmer??
    I am asking because I want to be as fair as possible to the applicant and not ask them questions which I think are tough etc...

    Touchy subject.
    The language is not as important, as understanding programming concepts.
    So fine, when the programmer's horizont involves some abstraction levels.
    If a programmer can write an UML class diagram for a linked list.
    If a programmer knows a design pattern Singleton.
    If a programmer can write his/her own single linked list class with sorted insertion.
    Language concepts:
    - Why:
    import java.util.*;
    Map map = new HashMap();
    - Answer:
    Hiding the choice of implementation (HashMap) by using the more general
    interface Map.
    Don't expect much on an interview though. The situation might not be
    adequate to distinghuish between the good and the bad apples.
    Talking code is a good starting point, code of your making unfortunately.
    A good programmer will hesitate to show really useful code.
    A bad programmer might have stolen his/her code.
    The problem you might have, that you are in search of an expert, not
    having the expertise in-house. In that case you might get a better
    picture, talking about which IDE would be opportune, whether he/she
    has experience with the source version system CVS, what would his/her
    ideas be about coming projects.
    That would establish a common line of communication.

  • What do you think of this book: "Programming and Problem Solving with Java"

    Hello Everyone:
    This may be a strange post but I am wondering if anyone has read this book and what do you think of it?
    Book Information
    Title: Programming and Problem Solving with Java
    Authors: Neell Dale, Chip Weens, Mark Headington
    Publisher: Jones & Bartlett
    Thanks for any comments

    No believe me the book is bad! The only reason I asked is I am in a university class that uses those two books for there course. The author messed up on HelloWorld.java with 4 errors at compile time! How can anyone be that stupid since they are the ones who are supposed to be teaching me the fundamentals of Java. Anyhow I just wanted other people's thoughts about the books.
    Thanks again for your input.

  • Challenging question! (Does anyone how to solve this Javabat question?)

    Does anyone how to solve this Javabat question?
    Here is the link:
    http://www.javabat.com/prob?id=Array3.linearIn

    I'm a little surprised by the implied rating of this problem... it's a plain to-way merge. You can use the same template as for the merging step in merge sort:
    public boolean linearIn(int[] outer, int[] inner) {
      int i = 0;
      int j = 0;
      while (i < outer.length || j < inner.length) {
          if (j < inner.length && (i == outer.length || inner[j] < outer)) {
    // inner[j] smallest
    return false;
    else if (i < outer.length && (j == inner.length || outer[i] < inner[j])) {
    // outer[i] smallest
    i++;
    else {
    // inner[j] == outer[i]
    i++; j++;
    return true;

  • Interesting Java Questions. Need answers Pls

    Hi All,
    I have come accross few java question, could any one please provide best answers please?
    1. Why the wait() method is there in the Object class? Not in the Threads?
    2. Why JDBC has all interfaces & not classes?
    3. Which type of collection do u prefer to make the incoming objects in sort order?
    4. Why the hasCode() method should be implemented if we are overiding the equals(0 method?
    Please provide me best answers ASAP.
    Girish.K

    do u prefer tohttp://www.catb.org/~esr/faqs/smart-questions.html#writewell
    How To Ask Questions The Smart Way
    Eric Steven Raymond
    Rick Moen
    Write in clear, grammatical, correctly-spelled language
    We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding (often enough to bet on, anyway). Answering questions for careless and sloppy thinkers is not rewarding; we'd rather spend our time elsewhere.
    So expressing your question clearly and well is important. If you can't be bothered to do that, we can't be bothered to pay attention. Spend the extra effort to polish your language. It doesn't have to be stiff or formal - in fact, hacker culture values informal, slangy and humorous language used with precision. But it has to be precise; there has to be some indication that you're thinking and paying attention.
    Spell, punctuate, and capitalize correctly. Don't confuse "its" with "it's", "loose" with "lose", or "discrete" with "discreet". Don't TYPE IN ALL CAPS; this is read as shouting and considered rude. (All-smalls is only slightly less annoying, as it's difficult to read. Alan Cox can get away with it, but you can't.)
    More generally, if you write like a semi-literate b o o b you will very likely be ignored. So don't use instant-messaging shortcuts. Spelling "you" as "u" makes you look like a semi-literate b o o b to save two entire keystrokes.

  • Any suggestions on solving the "java.lang.OutOfMemory" error message?

    Hi, our application is running on WLS61 and calls Tuxedo services (on Tuxedo 71)
    through WTC.
    What the problem we got is: about every 6-7 days, our application becomes out
    of functioning and the WTC call returns the "TPEINVAL - invalid arguments given".
    But in the "weblogic.log" file it logs the error message as
    "####<Sep 7, 2002 1:31:19 AM CDT> <Error> <Management> <awhq6394.whq.ual.com>
    <ECSserver> <Application Manager Thread> <> <> <000000> <Throwable while poller
    running>
    java.lang.OutOfMemoryError
    <<no stack trace available>>
    Please help us on the following questions:
    (1) From your experiences, is it really a Memory-Leak kind of problem or WTC-related
    problem, and if you have such experience, how did you solve the problem?
    (2)We use the DEFAULT value of "max-beans-in-cache" (to be 1000) for stateful
    and entity beans, and "max-beans-in-free-pool" (unlimited, depends on memory)
    for stateless beans. Does this might cause the POSSIBLE memory-leak problem? By
    the way, there are about 3000 transactions per day for our application.
    Also, please give us any suggestions you think is necessary.
    Thanks a lot!
    Bill

    - Do you get the error messages in jserv.log?
    - Have you read Note:119163.1 (How to set the heap size for the iAS/Jserv JVM) which ought to be avaliable on metalink?

  • Simple basic java question

    public static void main(String[] args)
    ..anyone know the statement as above could be start at begining , so what is the (String[ ] args) mean in java ?
    in my ideas of this statement is
    publc : indicates the statemean can be used as all class , this is open for public use
    static mean the main method can used as class method
    void indicate that the statement return nothing
    main indicate any class should be run this first.
    so my question what is the function of (String [ ] args) ? // one string array call args ?

    String[] args is indeed an array of Strings called args. The reason it's there is to collect any arguments passed to your code when you start it.
    eg. if you have a class called TestClass and you called it from the command line like this:
    java TestClass exam tomorrow oh shite
    .......then the args array would hold the four Strings:
    exam
    tomorrow
    oh
    shite

  • SOLVED VISTA JAVA 1.6.X 1.6.15 BROKEN JAVA CONSOLE IE8/FIREFOX HANGS

    I recently inherited a problem where JAVA was broken on Vista Home Premium whenever you hit the java test page
    www.*java*.com/en/download/help/*test*vm.xml*
    the browser for both IE8 and FireFox 3.5.2 would just hang which required a forced kill, trying to start the java console through the vista control pannel, for the latest build just failed 1.6.15.
    Trying to reinstall JAVA just failed, trying to downgrade JAVA  failed trying other possible incompatibilities upgrading to vista SP2 had no effect.
    Searching the web I found a number of hints then hit on what was the issue in that there was not one thing wrong but the JAVA install was broken in a number of places and so the problem was multi dimensional. The first task was figuring this out then gluing the pieces together
    *If your control panel for JAVA when clicked on barfs a warning ending with "{color:#ff0000}*com.sun.deploy.panel.ControlPanel"{color}* you need to fix this so you can easily access the JAVA configuration parameters
    1) First get the java console working put the following code into a file called in mycase javaconsole.bat amend it to suit your version/location of the javaw.exe file
    cd C:\"Program Files"\Java\jre6\bin javaw.exe
    {color:#0000ff} .\javaw -Xbootclasspath/a:..\lib\deploy.jar -Duser.home="%HOMEDRIVE%%HOMEPATH%" -Dsun.java2d.noddraw=true com.sun.deploy.panel.ControlPanel{color}
    This was based of the following thread, whats in blue is a single line
    http://forums.sun.com/thread.jspa?threadID=5372196
    2) Create short-cut, put this on you desk top double click and say yes to whatever UAC security issue Vista pop's up and console now comes up. The vista control panel icon will remain broken hence the batch script hack to access it
    3) Next piece is the java settings controlling the network, should java read the proxy settings from the browser itself FireFox/IE8. This needs to be set to {color:#ff0000}*direct*{color} if using a home network, that has no proxy infrastructure. This information was based of this following thread
    http://forums.sun.com/thread.jspa?threadID=5367053
    PS IE8 no longer has the JAVA enabled as option in it's own advanced section
    4) The above thread has the solution solved at the end as the :-
    "It was the default setting for the 'Network Proxy Settings' in the java control panel.
    The default setting 'Use browser settings' did not work for us.
    We changed it to 'Direct Connection' and now java works correctly."
    {color:#ff0000}*HOWEVER READ ALL THE ABOVE THREAD AND IT MENTIONS "the next-gen plugin."*{color}
    This is the last key in the puzzle as now you have the control panel working through the batch script also {color:#0000ff}*DISABLE the "Java Pluggin enabled the next generation Java Plug-in" under the security advanced tab*
    You will now have a working system for VISTA JAVA
    {color}
    Edited by: rmccorkl on Aug 23, 2009 11:25 AM

    jre 1.6.0_10 beta installtion fixes this problem!

  • Forte for Java question

    By using the JDBC form wizard, I generated a swing program. Along with the java code, there is a form file which looks like an xml file. My question is how to complie and run the java source code without a forte4j IDE?
    Thanks

    One thing is you need the jdbc in your classpath or specify at runtime. Search compiler in the forte help menu - to see options.
    execution : <specify at runtime>
    java -classpath:.;postgresql.org Program
    -- above for postgresql driver residing in same directory as Program.class
    compile : javac Progam.java or javac -classpath .;postgresql.org Progam.java
    Ray

  • TextSamplerDemo.java question

    I took the TextSamplerDemo from http://java.sun.com/docs/books/tutorial/uiswing/components/text.html and stripped it down to the one thing I have a question about. Given the code below, how do I implement the toolbar button to make selected text turn bold? I've been beating my head againt this one for a couple of days now and getting nowhere.
    Any help would be deeply appeciated.
    --gary
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*; //for layout managers and more
    import java.awt.event.*; //for action events
    public class TextSamplerDemo extends JPanel
    implements ActionListener {
    private String newline = "\n";
    protected static final String textFieldString = "JTextField";
    public TextSamplerDemo() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
    JToolBar toolBar = buildToolbar();
    add(toolBar);
    //Create a text pane.
    JTextPane textPane = createTextPane();
    JScrollPane paneScrollPane = new JScrollPane(textPane);
    paneScrollPane.setVerticalScrollBarPolicy(
    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    paneScrollPane.setPreferredSize(new Dimension(250, 155));
    paneScrollPane.setMinimumSize(new Dimension(10, 10));
    add(textPane);
    public void actionPerformed(ActionEvent e) {
    private JTextPane createTextPane() {
    String[] initString =
    { "This is an editable JTextPane, ",            //regular
    "another ", //italic
    "styled ", //bold
    "text ", //small
    "component, " + newline, //large
    "which supports embedded components..." + newline,//regular
    newline + "JTextPane is a subclass of JEditorPane that " + newline +
    "uses a StyledEditorKit and StyledDocument, and provides " + newline +
    "cover methods for interacting with those objects."
    String[] initStyles =
    { "regular", "italic", "bold", "small", "large",
    "regular", "regular"
    JTextPane textPane = new JTextPane();
    StyledDocument doc = textPane.getStyledDocument();
    addStylesToDocument(doc);
    try {
    for (int i=0; i < initString.length; i++) {
    doc.insertString(doc.getLength(), initString,
    doc.getStyle(initStyles[i]));
    } catch (BadLocationException ble) {
    System.err.println("Couldn't insert initial text into text pane.");
    return textPane;
    protected void addStylesToDocument(StyledDocument doc) {
    //Initialize some styles.
    Style def = StyleContext.getDefaultStyleContext().
    getStyle(StyleContext.DEFAULT_STYLE);
    Style regular = doc.addStyle("regular", def);
    StyleConstants.setFontFamily(def, "SansSerif");
    Style s = doc.addStyle("italic", regular);
    StyleConstants.setItalic(s, true);
    s = doc.addStyle("bold", regular);
    StyleConstants.setBold(s, true);
    s = doc.addStyle("small", regular);
    StyleConstants.setFontSize(s, 10);
    s = doc.addStyle("large", regular);
    StyleConstants.setFontSize(s, 16);
    private JToolBar buildToolbar() {
    JToolBar toolBar = new JToolBar();
    toolBar.setRollover( true );
    toolBar.setFloatable( false );
    JButton boldButton = new JButton("Bold");
    boldButton.setToolTipText( "Set selected text to bold" );
    boldButton.addActionListener( new ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    // code here to make selected text bold
    toolBar.add( boldButton );
    return toolBar;
    * Create the GUI and show it. For thread safety,
    * this method should be invoked from the
    * event-dispatching thread.
    private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Create and set up the window.
    JFrame frame = new JFrame("TextSamplerDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Create and set up the content pane.
    JComponent newContentPane = new TextSamplerDemo();
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.setContentPane(newContentPane);
    //Display the window.
    frame.pack();
    frame.setVisible(true);
    public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();

    try this, but im'not sure.
    StyleContext styleContext = StyleContext.getDefaultStyleContext();
    Style def = styleContext.getStyle(StyleContext.DEFAULT_STYLE);
    Style bold = styledDocument.addStyle("bold", def);
    StyleConstants.setBold(bold, true);into the listener of your component insert this:
    int start = getSelectionStart();
    int len = getSelectionEnd() - start;
    styledDocument.setCharacterAttributes(start, len, bold, true);by gino

  • Beginner Java questions

    Hello:
    I'm looking for some guidance on a few things I am confused on. Can somebody tell me or point me in the right direction on how you would write and equivalent compound statement for
    x = 2 * x;
    sum = sum + num;
    y = y / (x +5);
    lastly
    What type of input would I use for :
    import java.util.*;
    public class Strange
    static Scanner console = new Scanner (System.in);
    public static void main (String[ ] arg)
    int x;
    int y;
    String name:
    x = console.nextInt ();
    name = console.nextLine ();
    y = console.nextInt ();
    I appreciate any guidance and help provided on this. I'm struggling to wrap my head around some of these things.

    eaolson wrote:
    BigDaddyLoveHandles wrote:
    This is obviously a homework question. Please don't expect anyone here to do your homework for you.Well, if you notice, he's asking for "guidance" and for people to "point him in the right direction". He's not stating a problem and demanding a solution like so many others. If you ask me, he's asking for help with homework in exactly the right way.
    For the first question, I would suggest reviewing this section and the following ones of the Java Tutorials:
    http://java.sun.com/docs/books/tutorial/java/nutsandbolts/operators.html
    http://java.sun.com/docs/books/tutorial/java/nutsandbolts/op1.html
    I don't understand what the second question is asking for.In reply #2 the OP tried to clarify the second question:
    Well, I'm tasked wtith stating "what type of input the progragms requires and in what order the input must be provided" for the program I stated. >Beyond that, I'm not sure either and that's why I'm looking for help. "Looking for help", eh?

  • EDID and LUT - a java question

    Hi all!
    I just got my Mac Mini two days ago. I need some help in accessing certain informations to a java app I'm ought to write. I tried to google 'em up, but I got stuck. Maybe someone here could help me?
    1. How can I get EDID from my display? I've seen there's something called read-edid under linux, but I don't really know how close a relative Tiger is to linux/BSD.
    2. How can I write to LUT on my Mac?
    I suppose there are some libraries, that I can use, but I can't find them
    If not, maybe someone could direct me to a C library, so I can hopefuly run it via JNI.
    Any help would be greatly appreciated.
    TIA,
    Pablo

    blue-rose wrote:
    i don't see someone who want to help me =/ ,, if u don't want to ,, it's up to you ,, but there is no need for these words which u said to me ,, it really hurts ,, thanks all anyway =( ,,Seriously though, we help those that show that they are willing and able to do some work first. All you've posted was a classic "homework dump", and these are the typical responses to homework dump questions. Lesson learned.

  • 2 quick java questions

    hi, im working on a large grpahics project with some people, and i had a couple of simple questions.
    1) is it possible to detect the colour of a spefic pixel on an image?
    Maybe some sort of method that returns the color or something? This woudl be for collision detection, since we're going to have a character walking around a building and this is pretty much the only thing i can think of for collision.
    2) Is it possible to load a large image, and then make the screen only show a small portion of it? and then when you move, it kind of resets the focus on the larger image to your new location? This would be used to help the character move around the large map.
    Thanks for all the help!

    Youre going to want to get VERY acquainted with Image and BufferedImage, lol.
    Note the getRGB method.
    As for resizing, there are many ways to do this ranging from very simple
    to a bit complicated.
    int getRGB(int x, int y)
    Returns an integer pixel in the default RGB color model (TYPE_INT_ARGB) and default sRGB colorspace.
    http://java.sun.com/j2se/1.4.2/docs/api/java/awt/image/BufferedImage.html
    http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Image.html

  • 4 basic java questions..

    ok so I already learned Java last year (in grade 11), but my teacher didn't really teach anything, we learnt everything by ourselves from the API... so theres a lot of things I actually don't understand, but for now I want to ask 4 basic questions:
    1. What does static mean?
    2. Why would u "final" a constant variable? ie. If you have a variable called SIZE which is set to 5, so if u want it to be a constant, just never change its value. But what does the keyword final do to it?
    3. What's super? I see it sometimes, and my teacher showed us in the applet exampls to use super.paint(g) or somethign like that for the paint method, but I never use that because I noticed it works fine without it..
    4. Whats a question mark? I saw a game that was made in java and it had a lot of places where it had a question mark , which was part of the syntax. For example,
    int j1 = i != 0 ? i - 1 : 199;
    OR
    JUMPVEL = (fSuperSlime) ? 65 : 31;
    I really don't understand these lines...
    feel free to answer any of these questions...

    wow cool...thanks.. that question mark thing is nice
    saves a few lines..
    now, about super, so u mean u can access the parent
    class's variables?Variables, methods, constructors, if the access level is such that it's allowed.
    This will be covered in any tutorial or text though.
    Sun's basic Java tutorial
    Sun's New To Java Center. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    http://javaalmanac.com. A couple dozen code examples that supplement The Java Developers Almanac.
    jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    Bruce Eckel's Thinking in Java (Available online.)
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java.
    James Gosling's The Java Programming Language. Gosling is
    the creator of Java. It doesn't get much more authoratative than this.

Maybe you are looking for

  • Need to Create a Sales Order Using BAPI....

    Hello Gurus, I have called 'BAPI_SALESORDER_CREATEFROMDAT2' n a FM and trying to create a Sales Order. I have passed the header (auart, vkorg, vtweg, spart) and partner (nmbr and role). I passed the parameters to BAPI but in the return messages it sa

  • Mac Pro 2006 - Adding Wireless card

    Hi everyone I have a 2006 Mac Pro running Mac OSX 10.6 Snow Leopard. Back when I ordered the system, I chose Bluetooth but not WiFi Now I'm trying to add wireless to my Mac Pro, what are my options? Where can I find a wireless for my Mac Pro? Thank y

  • Need information on dbms_smtp

    Hi I got a requirement from office..that I need to send mails to customers. The customer who is reaching policy expire date, I have to send a mail to him/her. Seniors are given me this task. I have to complete this. I am new to his task. Please help

  • Listdata.svc Feed not returning correct sort order when you apply multiple sort functions.

    Hi, Am using the listdata.svc to access and update Sharepoint list. When i do the folowing query listdata.svc/ModuleItems?$inlinecount=allpages&$filter=substringof(%2781514db7-b340-478d-cf4e-d4ac608822e8%27,ReferenceID)&$orderby=ContentType,Created%2

  • Tables for Back Date Stock

    Hi, Abap Experts, I have to make a batch wise back dated stock report. Can any one help me to give name of stocks table for required query. Any help will be appresiable. Regards Rajiv singh.