Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Hey guys i've been trying to write this program for ages please Help!!

  1. #1
    Member
    Join Date
    Oct 2012
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Hey guys i've been trying to write this program for ages please Help!!

    how do i reverse an order of numbers starting with the input and working it's way down
    import java.io.*;
    import java.util.*;
     
    public class question4
    {
       public static void main(String[] args)throws IOException
       {
           // Set up an input buffer for reading input values
           BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
     
           // Set up an output buffer for writing results to
           PrintWriter output = new PrintWriter(System.out);
     
           // Read in values
           String line1 = input.readLine();
     
           // Convert string into int
    			 int x = Integer.parseInt(line1);
     
     
           // Output answers
           for(int i=0; i<=x;i+=3){
           output.println(i + " ");}
     
     
    			 // clean up output buffer
    			 output.flush();
       }
    }


  2. #2
    Member
    Join Date
    Oct 2011
    Posts
    114
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Hey guys i've been trying to write this program for ages please Help!!

    I think you would need i-- somewhere in there to decrement the integer one at a time.

    Is that what you want to do, so say 10 is entered you want to print, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0

    Or

    are you reading in a set of numbers and just reversing the order of how the numbers were typed.

    ''reverse an order of numbers starting with the input and working it's way down"

    Could you break this down further if possible ?

    How many numbers you want to read in as the input ?
    When exactly the input will terminate ?
    What you want to do with each individual number ? or do with a collection of numbers.
    etc. etc.

    Im just confused with the "working its way down" part you say.

  3. #3
    Member
    Join Date
    Oct 2012
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Hey guys i've been trying to write this program for ages please Help!!

    well it would be going down from the inputted number like if i inputted 24 and this program goes down in 3 then i would like it to 24,21,18,15,12,3,6,3,0 like that but i tried the i-- and i got an infinite loop unless i have to put in another loop then it wont work u get me?

Similar Threads

  1. Hey guys!
    By Shenaniganizer in forum Member Introductions
    Replies: 1
    Last Post: October 31st, 2012, 02:28 PM
  2. Hey guys:)))
    By mimka15 in forum Member Introductions
    Replies: 0
    Last Post: April 26th, 2012, 01:27 PM
  3. Hey guys! :D
    By goingforcoffee in forum Member Introductions
    Replies: 0
    Last Post: April 4th, 2012, 11:01 AM
  4. hey guys....
    By prince joseph in forum Member Introductions
    Replies: 2
    Last Post: March 27th, 2010, 11:15 PM
  5. Replies: 5
    Last Post: December 13th, 2009, 07:10 PM