Results 1 to 8 of 8
Like Tree1Likes
  • 1 Post By minibutmany

Thread: New to java need help please!!

  1. #1
    omesk10 is offline Member
    Join Date
    Oct 2014
    Posts
    2
    Rep Power
    0

    Lightbulb New to java need help please!!

    please help me figure this out i would highly appreciate it :)

    Write a java code that asks the user for an Integer and then counts down from that number to 0. Printing each number.

    For example:

    Enter an Integer: 5 (enter) <--- user hits the enter key
    5
    4
    3
    2
    1
    0



    import java.util.Scanner;

    public class Exam{
    public static void main(String args[]){
    Scanner in = new Scanner(System.in);

  2. #2
    minibutmany is offline Member
    Join Date
    Oct 2014
    Posts
    4
    Rep Power
    0

    Default Re: New to java need help please!!

    You are going to want a For Loop to count down.

    int count = in.nextInt();

    for(int index = in; index >= 0; index--)
    {
    System.out.println(index);
    }
    Last edited by minibutmany; 10-23-2014 at 02:10 AM.
    omesk10 likes this.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: New to java need help please!!

    It is frowned upon in this forum to spoon-feed solutions to folks so please don't do it. It is better to help them solve the problem themselves. Besides, your code is all wrong anyway.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    omesk10 is offline Member
    Join Date
    Oct 2014
    Posts
    2
    Rep Power
    0

    Default Re: New to java need help please!!

    Thank you!

  5. #5
    minibutmany is offline Member
    Join Date
    Oct 2014
    Posts
    4
    Rep Power
    0

    Default Re: New to java need help please!!

    Quote Originally Posted by jim829 View Post
    It is frowned upon in this forum to spoon-feed solutions to folks so please don't do it. It is better to help them solve the problem themselves. Besides, your code is all wrong anyway.

    Regards,
    Jim
    Whoops, the print line should print index not in.
    I've edited the post and checked the code and it compiles for me.
    Last edited by minibutmany; 10-23-2014 at 02:11 AM.

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: New to java need help please!!

    Quote Originally Posted by minibutmany View Post
    I've edited the post and checked the code and it compiles for me.
    Did you run it?

    Edit: Actually, it doesn't compile. Did you post different code? And don't change areas of your posts which have
    already been commented on. Another forum no-no. Please read the forum rules in the FAQ.

    Regards,
    Jim
    Last edited by jim829; 10-23-2014 at 02:56 AM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    minibutmany is offline Member
    Join Date
    Oct 2014
    Posts
    4
    Rep Power
    0

    Default Re: New to java need help please!!

    As you can see I edited my original post with correct code.

    Thanks for the warm welcome.

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: New to java need help please!!

    Quote Originally Posted by minibutmany View Post
    As you can see I edited my original post with correct code.
    Your posted and corrected code is not correct! It does not even compile. Even when I give
    it the proper Scanner object. The offending statement is:

    Java Code:
    for(int index = in; index >= 0; index--)
    in should be count.

    Quote Originally Posted by minibutmany View Post
    Thanks for the warm welcome.
    Sarcasm noted. And you're right! I could have been a little more diplomatic. But either you didn't
    read the rules before posting or you ignored them. And in spite of the rough beginning this is a
    great forum where you can learn quite a bit and have the potential to help others learn.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Tags for this Thread

Posting Permissions

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