Results 1 to 4 of 4
  1. #1
    Torgero is offline Member
    Join Date
    Oct 2008
    Posts
    33
    Rep Power
    0

    Default How can I make a loop, that writes a....

    sentence for every 10 line..

    I have a account class, and I want it to write out the interest every 15 year instead of each year as it does now..

    Here is what I got:

    PHP Code:
    class AccountTest{
    	public static void main(String [] args){
    
    		Konto MikeKonto = new Konto(12345, "Mike Tyson", 24, 10);
    
    		int teller = 0;
    		while (teller < 200){
    
    		MikeKonto.renteSats();
    
    		System.out.println("Saldo: " + MikeKonto.finnSaldo());
    
    		teller++;
    		}
    
    	}
    }
    The result it this:
    26.4
    29.0
    etc...

    What I want is to set the counter aka "teller" to 200 and have a written line only every 15 year or 20, instead of every year..
    "Rentesats" generates the rates every year, and is method in my Account class.. Konto means account.

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    if( ( loopIndex % 10 ) == zero )
    {
    print to receive buffer or file();
    }
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    Torgero is offline Member
    Join Date
    Oct 2008
    Posts
    33
    Rep Power
    0

    Default Ok, cheers..

    Ok, thanks... This is what I ended up with:
    PHP Code:
    Konto MikeKonto = new Konto(12345, "Mike Bob", 24, 10);
    
    		int teller = 0;
    		        while (teller < 250){
    
    		        MikeKonto.renteSats();
    
    		        	if(teller % 25 == 0){
    
    		        System.out.println("Saldo: " + MikeKonto.finnSaldo());
    
    				teller++;
    
    				}else{
    
    		        teller++;
    		        }
    			}
    Thanks alot..

  4. #4
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    6

    Default

    Java Code:
    if(teller % 25 == 0){ 
    
                    System.out.println("Saldo: " + MikeKonto.finnSaldo()); 
    
                    teller++; 
    
                    }else{ 
    
                    teller++; 
                    }
    what's this?
    use
    Java Code:
    if(teller % 25 == 0)
        System.out.println("Saldo: " + MikeKonto.finnSaldo()); 
    teller++;
    I die a little on the inside...
    Every time I get shot.

Similar Threads

  1. How to make a function?
    By mephisto772 in forum New To Java
    Replies: 5
    Last Post: 02-23-2009, 09:51 AM
  2. Make Change
    By Black.Ice. in forum New To Java
    Replies: 4
    Last Post: 12-18-2008, 07:12 AM
  3. Trying to make a GUI program
    By GettinGwap in forum New To Java
    Replies: 2
    Last Post: 11-04-2008, 11:37 PM
  4. files to make jar?
    By c0elh0 in forum New To Java
    Replies: 4
    Last Post: 10-31-2008, 12:04 PM
  5. i need help to make this program
    By masaka in forum New To Java
    Replies: 2
    Last Post: 03-23-2008, 01:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •