Help me with for loop please...............

hi guys i m just new bie as you know
i gotta print these things........
from 7 stars to 1 star........
i did it like this but it only produce
in this way,,,,,,
how do we actually padding the space and print it as the example........
help me guys whoever experts in for loops my code is........
class triangle
     public static void main (String[] args)
          a(7);
     public static void a (int num)
          for (int j = num ; j > 0 ; j--)
               for (int i = 0 ; i < j ; i++)
                    System.out.print("*");
               System.out.println ();
}

You really need a better screen name,
The problem is is that you want to print out a descending number of stars
preceded by a number of spaces . the number of spaces for a line is the number of characters - number of stars so
          for (int j = num ; j > 0 ; j--)
HERE print the required spaces!
               for (int i = 0 ; i < j ; i++)
                    System.out.print("*");
               System.out.println ();

Similar Messages

  • I feel ashamed but would someone help me with for loops?

    Hello all,
    Firstly, apologies. I feel ashamed. I am not new to programming but new to Java, so imagine my frustration at my blatant stupidity why I can't get this for loop to work....
    public void initGame(String[] arrTemp) {
    for (int i = 0; i > 4; i++) {
    frmGameOptions.append("hello" + arrTemp[i] + "-" + txtBully);
    basically the above method does not work!
    arrTemp does contain elements, trust me!
    it seems at though the loop isn't even getting entered!
    please help me!!!!!!!!!!!!!!!
    poncenby

    i think you want
    for (int i = 0; i < 4; i++)
        frGameOptions.append("hello" + arrTemp[i] + "-" txtBully);
    a better way would be
    for (int i =0; i < arrTemp.length; i++){
        frGameOptions.append("hello" + arrTemp[i] + "-" txtBully);
    }

  • Help needed with while loops please :)

    I'm beginning to study java at School.
    My assignment using while loops, to ask user to input 2 numbers.
    I have to output all odd number between the two.
    I have to output the sum of all even numbers between the two.
    Output all the numbers and their squares between 1-10.
    Output the squares of the odd numbers between the 2 numbers the user entered.
    Output all uppercase letters.
    If anyone can give me any help, I would appreciate it greatly.
    Thank you.
    Kelly.

    It would help if you put aside your code, and wrote out some pseudo-code first so that you understand the steps you will need to take. for example
    get input from user
    set counter to first number entered
    while counter less than/ equal to second number
          check if number is even
               if even, add to even_sum
               else output counter, along with its square
          increment counter by one
    end while
    output sum of evensthat block, when coded, will solve 3 of the problems, the other 2 will require separate loops
    Good Luck

  • Help needed with 'while' loop please

    Problem: When a non-integer is entered, the console displays "Enter a wager > java.util.InputMismatchException" intermitentlly.
    Here is the source codes
    ===================
    import java.util.Scanner;
    public class Test {
         private static int bankBalance = 1000;
         public static void main(String []args) {
              System.out.println("You entered: " + wager());
          Ask user for a wager, which must not be greater than 'bankBalance' and
          must be a valid Integer. Continue asking until a valid wager is entered.
         private static int wager() {
              Scanner scanner = new Scanner(System.in);
              int input = bankBalance + 1;
              boolean isValid = false;
              while( (input > 1000) || (isValid == false) ) {
                   try {
                        System.out.print("Enter a wager > ");
                        input = scanner.nextInt();
                        isValid = true;
                   } catch(java.util.InputMismatchException im_exc) {
                        System.out.println(im_exc.toString());
              return input;
    }

    It would help if you put aside your code, and wrote out some pseudo-code first so that you understand the steps you will need to take. for example
    get input from user
    set counter to first number entered
    while counter less than/ equal to second number
          check if number is even
               if even, add to even_sum
               else output counter, along with its square
          increment counter by one
    end while
    output sum of evensthat block, when coded, will solve 3 of the problems, the other 2 will require separate loops
    Good Luck

  • Help on changing array elements with For loop

    Hi,
    I'm wondering if anyone can help me with this problem.  I'd like to be able to modify elements of an array with For loop.  In the attached VI, my goal is to have an array of [0 1 2 3 4 5], but instead what I've got is [2 2 2 2 4 5].  I initialized the array with a value of 2 to help me identify which elements are changing.  Can anyone help me pointing where my mistake is?  Thanks.
    Peter
    Attachments:
    Array test.vi ‏19 KB

    It's a classic issue for LV newbies. In this case you HAVE to use a
    shift register otherwise the modifications of previous cicles are lost.
    It's all easier than it's seems, see attached vi.
    bye,
    manga
    Attachments:
    Array test 2.vi ‏19 KB

  • TS1424 I get "We could not complete your iTunes Store request. An unknown error occurred (4002)  Can any person help me with this on, please?

    I get "We could not complete your iTunes Store request. An unknown error occurred (4002)  Can any person help me with this on, please?

    Turning off iTunes Match and Genius and then turning them back on appears to have worked for some people e.g.
    https://discussions.apple.com/message/22059685#22059685
    https://discussions.apple.com/message/18427550#18427550

  • When I plug in my headphones into my imac only the right side plays music. I tried with other headphones and still has the same problem. I tried the headphones with other devices and they work properly. Can anyone help me with my problem please?

    When I plug in my headphones into my imac only the right side plays music. I tried with other headphones and still has the same problem. I tried the headphones with other devices and they work properly. Can anyone help me with my problem please?

    Macs have crazy headpne jacks in different models.
    So we know more about it...
    At the Apple Icon at top left>About this Mac, then click on More Info, then click on Hardware> and report this upto but not including the Serial#...
    Hardware Overview:
    Model Name: iMac
    Model Identifier: iMac7,1
    Processor Name: Intel Core 2 Duo
    Processor Speed: 2.4 GHz
    Number Of Processors: 1
    Total Number Of Cores: 2
    L2 Cache: 4 MB
    Memory: 6 GB
    Bus Speed: 800 MHz
    Boot ROM Version: IM71.007A.B03
    SMC Version (system): 1.21f4

  • PROBLEMS With my FOR LOOP , PLEASE HELP!!!

    Hello,
    I have the following event action button method. It has a loop itterates 10 times. I have an imagePanel of a map with an image of a car over the map. The car image moves with the method moveCar();
    MY PROBLEM: even though i have my moveCar() method inside the for loop, it doesnt move the car on the map until the loop is finished executing and the car image just jumps over. Can somebody pleae tell me why it does this and how to fix it?????????? thanks so much       public ActionListener startActionListener() {
             ActionListener listener = new ActionListener() {
             public void actionPerformed(ActionEvent event) {
             for (int i=0; i<10; i++) {
                             imagePanel.moveCar();
                        try {
                             Thread.sleep(1000); //waits approx. 1 second
                        } catch (InterruptedException e) {
                             System.exit(0);
               return listener;
         }thanks!

    Well, the easiest way is like this:
    public ActionListener startActionListener()
         ActionListener listener = new ActionListener()
              public void actionPerformed(ActionEvent event)
                   new Thread(new Runnable()
                        public void run()
                             for (int i=0; i<10; i++)
                                  imagePanel.moveCar();
                                  imagePanel.repaint();
                             try
                                  Thread.sleep(1000); //waits approx. 1 second
                             catch (InterruptedException e)
                                  //System.exit(0);
                   }).start();
              return listener;
    }I simply converted your loop to run asynchronously and added a call to repaint after the move. You would be better off to use a Swing Timer instead, but I will leave that to you.

  • Problem with while loops, please help!

    I am having quite a bit of trouble with a program im working on. What i am doing is reading files from a directory in a for loop, in this loop the files are being broken into words and entered into a while loop where they are counted, the problem is i need to count the words in each file seperately and store each count in an array list or something similar. I also want to store the words in each file onto a seperate list
    for(...)
    read in files...
         //Go through each line of the first file
              while(matchLine1.find()) {
                   CharSequence line1 = matchLine1.group();
                   //Get the words in the line
                   String words1[] = wordBreak.split(line1);
                   for (int i1 = 0, n = words1.length; i1 < n; i1++) {
                        if(words1[i1].length() > 0) {
                             int count= 0;
                                           count++;
                             list1.add(words1[i1]);
              }This is what i have been doing, but with this method count stores the number of words in all files combined, not each individual file, and similarly list1 stores the words in all the files not in each individual file. Does anybody know how i could change this or what datastructures i could use that would allow me to store each file seperately. I would appreciate any help on this topic, Thanks!

    Don't try to construct complicated nested loops, it makes things a
    tangled mess. You want a collection of words per file. You have at least
    zero files. Given a file (or its name), you want to add a word to a collection
    associated with that file, right?
    A Map is perfect for this, i.e. the file's name can be the key and the
    associated value can be the collection of words. A separate simple class
    can be a 'MapManager' (ahem) that controls the access to this master
    map. This MapManager doesn't know anything about what type of
    collection is supposed to store all those words. Maybe you want to
    store just the unique words, maybe you want to store them all, including
    the duplicates etc. etc. The MapManager depends on a CollectionBuilder,
    i.e. a simple thing that is able to deliver a new collection to be associated
    with a file name. Here's the CollectionBuilder:public interface CollectionBuilder {
       Collection getCollection();
    }Because I'm feeling lazy today, I won't design an interface for a MapManager,
    so I simply make it a class; here it is:public class MapManager {
       private Map map= new HashMap(); // file/words association
       CollectionBuilder cb; // delivers Collections per file
       // constructor
       public MapManager(CollectionBuilder cb) { this.cb= cb; }
       // add a word 'word' given a filename 'name'
       public boolean addWord(String name, String word) {
          Collection c= map.get(name);
          if (c == null) { // nothing found for this file
             c= cb.getCollection(); // get a new collection
             map.put(name, c); // and associate it with the filename
          return c.add(word); // return whatever the collection returns
       // get the collection associated with a filename
       public Collection getCollection(String name) { return map.get(name); }
    }... now simply keep adding words from a file to this MapManager and
    retrieve the collections afterwards.
    kind regards,
    Jos

  • So close but need help comparing strings in different subforms with for loop - Livecycle ES

    For some reason I was not able to post this in the Livecycle ES forum, even though I've posted there often in the past.
    I have created a form that I almost have working and I'm hoping someone can help me.
    We have eight billing teams in our company and each team works anywhere from 1 - 4 different clients. The form is used to track, per Billing Rep, the number of items of mail that each billing r5ep works each day. What I'm needing to add at the bottom is a subform that tracks the totals by client. So I'm trying to get the form to loop through all of the existing subforms (and the subforms within them) and compare a cell int he bottom subform to a cell in the other subforms, which are dynamically added, and then total ONLY those items. My script however is not working.
    What I have now is:
    var repCount = form1.P1._rep.count
    var itemCount = form1.P1.rep._ItemSet.count
    for (x=0; x<repCount; x++)
         for (i=0; i<itemCount; i++)
              if(clientName.rawValue == P1.rep[x].ItemSet[i].client.rawValue)
              this.rawValue = this.rawValue + P1.rep[x].ItemSet[i].corresp.rawValue;
    It seems like this should work but I'm getting the following error:
    P1.rep[x] is undefined
    So what it looks like is I'm missing is the proper way to reference the objects in these subforms.
    The form is here: https://acrobat.com/#d=20gWXZ4sBm4OPV6oO76zSg
    If someone could take a look at it I would be so grateful.
    Thanks,
    Jo

    I don't know that anyone else will ever have a similar problem as what I was having, but I figured I would go ahead and post the solution, just in case....
    The error I was getting (P1.resolveNode("rep[" + j + "].ItemSet[" + i + "]") is null) was occuring because the variable itemCount needed to be referenced within the repCount For Loop. I also needed to resolve the node for the itemCount, which I wasn't doing.
    So...my old code was this:
    var repCount = P1._rep.count;
    var itemCount = P1.rep._ItemSet.count;   //this part was throwing the error. Needed to use resolveNode...and needed to not declare the variable until inside the first For Loop.
    var nTotal = 0;
    for (var j=0; j<repCount; j++) {
        for (var i=0; i<itemCount; i++)    {
            if (P1.resolveNode("rep["+ j +"].ItemSet["+ i +"]").client.rawValue == clientName.rawValue) {
                nTotal = nTotal + P1.resolveNode("rep["+ j +"].ItemSet["+ i +"]").corresp.rawValue;
    this.rawValue = nTotal;
    ...which wasn't working because it was trying to reference the count of the ItemSet right up front...but it needed to wait until it got inside the first iteration of the repCount subfields...AND it needed to have resolveNode used.
    The corrected code is:
    var repCount = P1._rep.count;
    this.rawValue = 0;
    for (var j=0; j<repCount; j++) {
        var itemCount = P1.resolveNode("rep["+j+"]")._ItemSet.count;  //corrected code...node is resolved and variable is declared within the first subform repCount.
        for (var i=0; i<itemCount; i++)    {
            if (P1.resolveNode("rep["+ j +"].ItemSet["+ i +"]").client.rawValue == clientName.rawValue) {
                this.rawValue = this.rawValue + P1.resolveNode("rep["+ j +"].ItemSet["+ i +"]").corresp.rawValue;
    ...which now works perfectly...and I'm throwing a party to celebrate! LOL
    Jo

  • Visa open and close with "for loops"

    Hello everyone
    In my program I used two "for loops" which include visa write and read for a RS32 port. it is not possible to close a devise with visa close as the out put is changed to 2D array!!! would you please help me with this error
    Attachments:
    ACU_232.png ‏108 KB

    sam009 wrote:
    Thanks for reply,
    It works for "for loop" but what about "event structure loop" still is error for that. 
    Right-click on the output tunnel and uncheck "Use Default if Unwired".  You will now be forced to wire the VISA Resource through each case.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Need help in creating for loop

    Hi,
    I want to create two different Xquery transformation by checking attribute value in the input xml.
    <n:DIAMessage xsi:schemaLocation="http://pearson.com/DIA C:/shashi/rewrite/DIA/DIA_Schemas/DIA_new.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:n="http://pearson.com/DIA">
    <n:Customer>
    <n:Account sourceClassName="Account" sourceInstanceID="01560900" sourceSystem="MDR">
    <n:hasAccountRelation sourceClassName="AccountRelation" sourceInstanceID="01560900" sourceSystem="MDR">
    <n:hasAccountPerson name="BRIAN C STRICKLAND" sourceClassName="Person" sourceInstanceID="01560900|$|00114" sourceSystem="MDR"/>
    </n:hasAccountRelation>
    </n:Account>
    <n:Account sourceClassName="Account" sourceInstanceID="01560900" sourceSystem="MDR">
    <n:hasAccountRelation sourceClassName="AccountRelation" sourceInstanceID="01560900" sourceSystem="MDR">
    <n:hasAccountPerson name="BRIAN C STRICKLAND" sourceClassName="Person" sourceInstanceID="01560900|$|00114" sourceSystem="MDR"/>
    </n:hasAccountRelation>
    </n:Account>
    <n:Person name="BRIAN C STRICKLAND" sourceClassName="Person" sourceInstanceID="01560900|$|00114" sourceSystem="MDR">
    <n:hasIdentifier sourceClassName="Identifier" sourceInstanceID="01560900|$|00114" sourceSystem="MDR">
    <n:IDType>GENDER</n:IDType>
    <n:IDTypeName>GENDER</n:IDTypeName>
    <n:IDValue>M</n:IDValue>
    </n:hasIdentifier>
    </n:Person>
    <n:Person name="BRIAN C STRICKLAND" sourceClassName="Person" sourceInstanceID="01560900|$|00114" sourceSystem="MDR">
    <n:hasIdentifier sourceClassName="Identifier" sourceInstanceID="01560900|$|00114" sourceSystem="MDR">
    <n:IDType>GENDER</n:IDType>
    <n:IDTypeName>GENDER</n:IDTypeName>
    <n:IDValue>M</n:IDValue>
    </n:hasIdentifier>
    </n:Person>
    </n:Customer>
    </n:DIAMessage>
    From the above Message i need to create two transformation by checking
    if (DIAMessage/Customer/Account/@sourceClassName="Account")
    then call {
    Xquery1
    if(DIAMessage/Customer/Person/@sourceClassName="Person")
    then call{
    Xquery2
    Constraint here is Account and Person block occurence will be many times.As they are in same hierarchy how to create a for loop concept here?
    Please anyone can help me on this?

    Hi,
    Create a numeric variable to act as While loop counter and assign value of 1. Create a boolean variable to act as a flag to exit loop and assign value of true.
    Create a while object with a condition that while flag variable is true loop.
    Then you can create a switch with a case for each of your scenarios, referencing the xth record (defined by loop counter variable) in xml using ora:getElement
    When the count of required elements in input xml is less than your loop variable, assign the variable to exit loop as false...otherwise increment counter by one to loop to next record.
    Hope this helps.

  • Hey guy can you please help me with this issue PLEASE!

    Hey Apple can you please help me with this issue, i have a iPhone 3gs and when i put my sim card into the iPhone it makes iphone 3gs shut down suddenly how do i fix that?
    iPhone version: 6.0.1
    service provider: Vodafone nz

    You could restarting your phone that sometimes fixes issues
    Hold down the Sleep/Wake button and the home button together until the apple logo appears (ignore the ON/OFF slider) then let both buttons go and wait for phone to restart (no data will be lost).

  • Help needed with Synergy 4500 please

    I have inherited a set of BT Synergy 4500 phones and have been trying to get them set up but am having problems - can somebody please give me some help?
    First, there are three handsets but one is showing as number 4, (I suspect there might have originally been 4 but one has disappeared).  I've been trying to renumber this but no luck.
    When I lift the phone to make a call I get a noise that sounds like an engaged tone - not like an ordinary dial tone, and I can't seem to dial out - nothing happens.
    One of the handsets indicates there are three unanswered calls - how can I clear this? 
    TIA 

    There are help pages here http://bt.custhelp.com/app/answers/detail/a_id/11489/~/bt-synergy-4500
    The guide should tell you how to clear the calls.
    There are some useful help pages here, for BT Broadband customers only, on my personal website.
    BT Broadband customers - help with broadband, WiFi, networking, e-mail and phones.

  • HT1212 I don't remember the password of my iphone. I restarted the phone with IOS 7. But I can't remember what the password was. Help me with my problem please.

    I don't remember the password for my iphone 4. I restated it with IOS 7 and the iphone is disable.Please help me with that.

    You will have to restore it from Recovery mode, as described in the tip you were reading when you posted your message. Or see: http://support.apple.com/kb/HT1808. You will lose all data on your phone.

Maybe you are looking for