Results 1 to 3 of 3
  1. #1
    ramin is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Make a loop that prints the lastnumber only

    Hi
    I just started with java course and are not very knowledgeable
    I am stuck on a task that I think is very easy for all java expert here.


    The task wants me to make the loop only print the last number, and not all numbers.
    it is surely very easy but I am stuck and have to submit the task as quickly as possible.
    someone who can help me with that?

    THis is the loop:


    for(int i = 0; i <= 5; i++){
    int lastNumber = 0;
    lastNumber = i;
    System.out.println(lastNumber);
    }
    Last edited by ramin; 04-06-2012 at 03:12 AM.

  2. #2
    Wnt2bsleepin is offline Senior Member
    Join Date
    Feb 2012
    Posts
    219
    Rep Power
    3

    Default Re: Make a loop that prints the lastnumber only

    Could you provide sample output? That code there should print out the variable i until it stops at 5.

  3. #3
    ramin is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Re: Make a loop that prints the lastnumber only

    I am sorry that was wrong this is the right loop

    for(int i = 0; i <= 5; i++){
    int lastNumber = 0;
    lastNumber = i;
    System.out.println(lastNumber);
    }

Similar Threads

  1. Txt to ArrayList only prints []
    By Quasi Urbane in forum New To Java
    Replies: 4
    Last Post: 04-27-2011, 07:16 PM
  2. Canvas Prints
    By canvas02 in forum Reviews / Advertising
    Replies: 0
    Last Post: 02-18-2011, 05:33 PM
  3. List prints only the first row repeatedly in a loop
    By yss1287b in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 11-16-2010, 02:21 PM
  4. Count each cell as it prints.
    By Shyamz1 in forum New To Java
    Replies: 9
    Last Post: 10-29-2010, 12:58 AM
  5. How can I make a loop, that writes a....
    By Torgero in forum New To Java
    Replies: 3
    Last Post: 03-10-2009, 04:45 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
  •