PLEASE HELP!! For and While structure

I am trying to do the exercise 5.11 from Java Deitel 4th edition it says
"Write an applet that reads five numbers, each between 1 and 30. For each number read, your program should draw a line containing that number of adjacent asterisks. For example, if your program reads the number 7, it should display *******."
The problem:
The program asks me twice ONLY for the first number I don't know why? The logic is good, I think is something related with the scope of the variables or something particular with Java I don't know jet.
This is my code:
// Java core packages
import java.awt.Graphics;
// java extension packages
import javax.swing.*;
public class Exe5_11 extends JApplet {
public void paint( Graphics g )
int number;
String input;
super.paint( g );
JTextArea outputTextArea = new JTextArea();
outputTextArea.setText("Hystograms\n\n");
for ( int i = 1; i <= 5; i++ ) {
number = 0;
while ( number > 30 || number < 1) {
input = JOptionPane.showInputDialog("Enter Number " + i );
// convert user's input to an int
number = Integer.parseInt( input );
} // end while input
// display asterisks
for ( int j =1; j <= number; j++) {
outputTextArea.append ("*");
outputTextArea.append ("\n");
} // end for
JOptionPane.showMessageDialog( null, outputTextArea,"Hystograms", JOptionPane.INFORMATION_MESSAGE );
System.exit(0);
} // end paint method
} // end class Exe5_11Samuel

Not sure why,but this works instead...
// Java core packages
import java.awt.Graphics;
// java extension packages
import javax.swing.*;
public class Exe5_11 extends JApplet
     int number;
     String input;
     JTextArea outputTextArea = new JTextArea();
     public void init()
          outputTextArea.setText("Hystograms\n\n");
          for ( int i = 1; i <= 5; i++ ) {
               number = 0;
               input = JOptionPane.showInputDialog("Enter Number " + i );
               // convert user's input to an int
               number = Integer.parseInt( input );
               while ( number > 30 || number < 1)
                    input = JOptionPane.showInputDialog("Enter Number " + i );
                    // convert user's input to an int
                    number = Integer.parseInt( input );
               } // end while input          
               // display asterisks
               for ( int j =0; j < number; j++) {
                    outputTextArea.append ("*");
               outputTextArea.append ("\n");
          } // end for
     public void paint(Graphics g)     
          JOptionPane.showMessageDialog( null, outputTextArea,"Hystograms", JOptionPane.INFORMATION_MESSAGE );
     } // end paint method
} // end class Exe5_11

Similar Messages

  • I need to by apps but it keeps asking for my security questions ;/ but  forgot the answers to my security questions and the security/rescue email too (i dont have USA number to call please help me and send my rest to my email

    I need to by apps but it keeps asking for my security questions ;/ but  forgot the answers to my security questions and the security/rescue email too (i dont have USA number to call please help me and send my rest to my email

    You need to ask Apple to reset your security questions. To do this, click here and pick a method; if that page doesn't list one for your country or you're unable to call, fill out and submit this form.
    (115668)

  • PIXMA MX432. I can't print now. I only get the "please wait for a while.

    I installed a new ink cartridge in my PIXMA MX432. I can make copies just fine, but I can't print. I only get the "please wait for a while" message.

    Hello TomClark.
    For testing purposes, please turn the printer off and back on.  Then restart your computer.  Once this has been done, try printing again. 
    If the error persists, please contact our support group using the "Contact Us" link below for additional assistance.
    This didn't answer your question or issue? Find more help at Contact Us.
    Did this answer your question? Please click the Accept as Solution button so that others may find the answer as well.

  • I just want to ask if there is any way i can fix my ipod touch 4G from watar damage and i dont think that a larg amount of water have entered and the ipod isnt working at all and i tried charging it but it didnt work so please help me, and thankyou.

    I just want to ask if there is any way i can fix my ipod touch 4G from watar damage and i dont think that a larg amount of water have entered and the ipod isnt working at all and i tried charging it but it didnt work so please help me, and thankyou.

    Probably dead if you have tried to charge it.
    You should never try to charge or turn on a wet electronic device.
    You should let it dry for  a week or so, then try.

  • Incorporate: For, and while loop,a nested pair for both,and to add graphics

    // I have done the class but
    need help one adding one while loop, one for loop, and a nested pair loops using for and while, and if posbile to add on a dynamite graphics. // i am doing this for a brithday present for my brother who is a java programer
    and would be happy to see his little brother make a java programe for him
    //class file
    import java.awt.*;
    public class ZZZCalculator
            private double amount;
            public ZZZCalculator (double x)
                    amount= x;
            public void addAmt (double inputNumber)
                    amount= amount +inputNumber;
            public void divideAmt (double inputNumber)
                    amount=amount/inputNumber;
            public void subtractAmt (double inputNumber)
                    amount=amount-inputNumber;
            public void multiplyAmt (double inputNumber)
                    amount=amount*inputNumber;
            public void display (Graphics g)
                    g.drawString (""+ amount, 150,100);
            public void setAmt(double x)
                    amount= x;
      // Pgm file
    import java.awt.*;
    import java.applet.Applet;
    import java.awt.event.*;
    public class ZZZCalc extends Applet implements ActionListener {
            ZZZCalculator henrietta;
            TextField amtPlace;
            Button adder;
            Button divide;
            Button subtract;
            Button multiply;            
            public void init()
                    henrietta=new ZZZCalculator(0.0);
                    amtPlace=new TextField(10);
                    amtPlace.addActionListener(this);
                    add(amtPlace);
                    adder=new Button ("+");
                    adder.addActionListener(this);
                    add(adder);
                    divide=new Button ("/");
                    divide.addActionListener(this);
                    add(divide);
                    subtract=new Button ("-");
                    subtract.addActionListener(this);
                    add(subtract);
                    multiply=new Button ("*");
                    multiply.addActionListener(this);
                    add(multiply);
            public void paint (Graphics g)
                    g.drawString("amount:", 100,100);
                    henrietta.display(g);
            public void actionPerformed(ActionEvent e)
                    if (e. getSource()==amtPlace)
                    double amt= Double.parseDouble (amtPlace.getText());
                    henrietta.setAmt(amt);
                    repaint();
                    if(e.getSource()==adder)
                    double amt= Double.parseDouble (amtPlace.getText());
                    henrietta.addAmt(amt);
                    repaint();
                    if(e.getSource()==divide)
                    double amt= Double.parseDouble (amtPlace.getText());
                    henrietta.divideAmt(amt);
                    repaint();
                    if(e.getSource()==subtract)
                    double amt= Double.parseDouble (amtPlace.getText());
                    henrietta.subtractAmt(amt);
                    repaint();
                    if(e.getSource()==multiply)
                    double amt= Double.parseDouble (amtPlace.getText());
                    henrietta. multiplyAmt(amt);
                   repaint();
    //thank you for the help
    i have just started working on java and this is my frist program i am working on and any help i can get would inprove my understanding of java.
    Thank you very much for you help

    hey there... this is Rebecca
    try this somewhere in the prog.
    n = Math.pow(x,y)
    where n is an int you declare...
    and x and y are the numbers... as in
    n = 10^3
    where 10 = x and 3 = y

  • Please help for my iphone 4 unlock

    please help for my iphone 4 unlock

    Apple store said my iPhone 4 had an LCD issue and that is why slide to unlock is frozen.  My warranty ran out so it would cost approx. $150 to repair it he said.  Time for a new phone but not sure I want another iPhone now.

  • HT5312 I forget answer to my qustion with rescue email adrees please help me and send the answer to my main mail. Thank you very much

    I forget answer to my qustion with rescue email adrees please help me and send the answer to my main mail. Thank you very much

    We are fellow users here on these forums, you're not talking to iTunes Support.
    If you don't have access to your rescue email account, or you don't have one on your iTunes account, then you will need to contact iTunes Support / Apple to get the questions reset.
    Contacting Apple about account security : http://support.apple.com/kb/HT5699
    When they've been reset you can then use the steps half-way down this page to add/change a rescue email address for potential future use : http://support.apple.com/kb/HT5312

  • Please Help for the Query

    Please Help for the Query
    Hi frds please help me for the below query.What I want to do is to pull out the data from below table :-
    date ticker indicator
    03/13/2008 3IINFOTECH -8
    03/18/2008 3IINFOTECH -4
    03/25/2008 3IINFOTECH -5
    03/27/2008 3IINFOTECH -3
    as such :-
    date ticker indicator
    03/13/2008 3IINFOTECH -8
    03/25/2008 3IINFOTECH -5
    03/27/2008 3IINFOTECH -3
    Here I want to find the Trend i.e either asc or desc order from the lowest indicator.
    In the above sample data -8, -4, -5, -3 out of which I want the asc order data -8, -5, -3 and exclude -4 data.Because the asc order -8, -5, -3 will not follow.
    So I want the data
    date ticker indicator
    03/13/2008 3IINFOTECH -8
    03/25/2008 3IINFOTECH -5
    03/27/2008 3IINFOTECH -3

    SQL> CREATE TABLE BORRAME(FECHA DATE, INDICA VARCHAR2(100));
    Tabla creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/13/2008','MM/DD/YYYY'), '3IINFOTECH -8');
    1 fila creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/18/2008','MM/DD/YYYY'), '3IINFOTECH -4');
    1 fila creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/25/2008','MM/DD/YYYY'), '3IINFOTECH -5');
    1 fila creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/27/2008','MM/DD/YYYY'), '3IINFOTECH -3');
    1 fila creada.
    SQL> COMMIT;
    Validación terminada.
    SQL>
    SQL> SELECT FECHA, INDICA
      2  FROM BORRAME
      3  WHERE SUBSTR(INDICA,INSTR(INDICA,'-',1)+1,LENGTH(INDICA)) <> '4'
      4  ORDER BY SUBSTR(INDICA,INSTR(INDICA,'-',1)+1,LENGTH(INDICA)) DESC;
    FECHA                                                                
    INDICA                                                               
    13/03/08                                                             
    3IINFOTECH -8                                                        
    25/03/08                                                             
    3IINFOTECH -5                                                        
    27/03/08                                                             
    3IINFOTECH -3                                                        
                    

  • Hi,my ICloude is locked and canot use my Phone. Please, help me and answer me. Mira

    Hi, my name is Mira Ćenan. I from Zagreb,Croatia.
    My ICloude is locked and canot use my Phone. Please help me and answer me.
    Thank you!
    Mira

    Only the person who initiated the Activation Lock can remove it. Contact the seller/
    previous owner for assistance. There is no workaround for Activation Lock.

  • Help....I am trying to set up iClould on my pc....the set up was complete....when I try to sign in to set up it says the Apple ID is valid but is not an iCloud account.  Please help me and tell me what I am doing wrong.

    Help....I am trying to set up iClould on my pc....the set up was complete....when I try to sign in to set up it says the Apple ID is valid but is not an iCloud account.  Please help me and tell me what I am doing wrong. Thx

    Hi DesCoop,
    You must initiallly activate iCloud from an IOS device or a Mac. You cannot inititally activated from a PC.
    Sorry.
    GB

  • Hello. Please help. for unknow reasons, I am not getting any of my mail on anything, nothing on my iphone, my outlook or even when I log into icloud online ???   any one else having troble??   please help   I need my mail

    Hello. Please help. for unknow reasons, I am not getting any of my mail on anything, nothing on my iphone, my outlook or even when I log into icloud online>???
    any one else having troble??
    please help
    I need my mail

    Hello, DragonStudios. 
    Thank you for visiting Apple Support Communities.
    Here are a couple troubleshooting resources I would recommend when experiencing issues with iCloud Mail.
    iCloud: Troubleshooting iCloud Mail
    http://support.apple.com/kb/TS4002
    iCloud: Account troubleshooting
    http://support.apple.com/kb/TS3988
    Cheers,
    Jason H.

  • I lost my iPhone 3 days ago.. it wasn't connet to internet and I don't know how find it without the connection.. please help me and give me some advices!!

    I lost my iPhone 3 days ago.. it wasn't connet to internet and I don't know how find it without the connection.. please help me and give me some advices!!

    Change your passwords.

  • Please help! Invalid node structure and invalid record count

    My MacBook Pro is about 6.5 years old. I upgraded to Snow Leopard 2 years ago and added RAM at the same time. My first problem ever occurred three days ago when my computer got super sluggish, I restarted and got the gray screen with apple and spinning wheel...no boot up. I ran disk utility from the snow leopard install disk and found "invalid node structure" and "invalid record count". After reading on here what to do...try to repair the disk and so on with no success I went out and bought Disk Warrior. Got home expecting to fix everything and Disc Warrior won't boot...I just get a file with a question mark and the disc is ejected. I tried erasing the hard drive but was only able to use the "don't erase data" option. Then I tried to reinstall Snow Leopard with no luck. Now I am stuck. Any ideas? 
    One thing to note is I am to the point of not caring about the files on the hard drive, I was a dummy and never backed them up...lesson learned!  I just want my computer back without having to spend $1000+ for a new one. Then again I am always willing to do that too as a last resort.
    PLEASE HELP!

    When you contact Alsoft, make sure you let them know that you are using Snow Leopard (10.6.8).
    Try the following in the meantime -
    Disconnect all peripherals from your computer.
    Boot from your install disc & run Repair Disk from the utility menu. To use the Install Mac OS X disc, insert the disc, and restart your computer while holding down the C key as it starts up.
    Select your language.
    Once on the desktop, select Utility in the menu bar.
    Select Disk Utility.
    Select the disk or volume in the list of disks and volumes, and then click First Aid.
    Click Repair Disk.
    Restart your computer when done.
    Repair permissions after you reach the desktop-http://support.apple.com/kb/HT2963 and restart your computer.
    Try DiskWarrarior again if it's combatible with the os system.
    YOu cannot reformat until you get your issue corrected.

  • Please help for my unexpected shutdown W510!!!

    Since I used my W510 ( 43192NU with Windows 7 32bit ) from April 2010, I did experienced with unexpected shutdown. First, I thought it was my improperly use. But now, it shutdown unexpectedly even 3 times a week. Did anyone got the same experienced? Please help me...

    I have the same exact problem!!!
    And it drives me crazy.
    It happens only when my battery is charging (that is, it's not at 100%).
    If the battery is fully charged, and I'm on AC power as well, all works o.k., but as soon as the battery is low (say 50%) and I plug it in, and put some load on the system (using VMware a lot) it runs for a while then dies instantaneously. No gradual shut-down - just shuts off.
    It just happened again a few minutes ago, and I lost an important VMware file.
    I called Lenovo support a few months ago, and they wanted me to send the laptop in for a week to make sure there is really a problem.
    Any other input/comments would be appreciated.
    BTW, I purchased the W510 in February 2010.

  • Please help for ORA-02049 - Timeout error

    Hi All,
    we have got a reporting DB and 14+ Application DBs, the data is extracted from all the application databases (DBs) and dumped into the common tables of reporting database. While inserting and updating the common reporting tables the other jobs gets timeout error and fails. We daily face this failure problem (error: ORA-02049 - Timeout error distributed transaction waiting for lock) for almost 10-15 times.
    Can you please help me out in resolving and getting the permanent solution for this problem.
    Thanks in advance.

    Thanks Kamal,
    as mentioned above, I have got Oracle,Java,Unix environment. Autosys jobs are scheduled through out the day.
    Mechanism : Autosys job triggers the action at specified time, Unix code calls oracle packaged procedure, extracts data and puts into the common reporting table from this data java code formats the report output.
    There are separate reporting jobs for all instances though the report is same but for different locations(14 DB instances).
    and all these reporting jobs dump data into common reporting table, data can be differentiated on the hub or location.
    But if one job is running for first instance then second job waits for the lock and fails after 2 mins.
    I have to avoid this situation, I hold I am able to explain the situation.

Maybe you are looking for

  • Give Me Some Tips For doing this report.

    hi frd. help me in this report. parameter : plant,material no,company code,storage location. display: material no, material desc, UOM, ROL, warehouse, open po, open po qty, open pr no, open pr qty. Kindly Give me tips for doing this report. thank u P

  • How do you protect the content in a chm?

    Hello, I know some users have thought of some creative techniques for preventing content from being copied from a chm, spefically Pete Lee's JavaScript methods. However, I was wondering if anyone knew how to append a copyright statement when the cont

  • Showing multiple popups

    Hey all, I am trying to implement my own menu system by subclassing JMenu, JMenuItem, and JPopupMenu. Everything works fine, except for one glitch: when what should be a submenu opens, the main menu closes because they are both popups and swing only

  • Standalone OC4J 9.0.4 - Loading Native Libraries - Unsatisfied Link Error

    Hello, I incidentally happen to have a similar problem as has been described in several posts in this forum. The problem is that of loading Native libraries in OC4J. The scenario is 1) Environment is Standalone OC4J 9.0.4, Windows 2000, JDK 1.4.2 2)

  • Usando Iphone4 com o Wireless-speedy

    Por favor.. alguem poderia me ajudar? Acabo de comprar meu Iphone4 pela claro, com banda de 1Giga. Porem, em casa eu conecto pelo meu Wireless do Speedy. Qdo eu estiver conectada pelo Wireless do speedy e puxar arquivos e programas eu gasto tb a band