Results 1 to 6 of 6
  1. #1
    xlactyu is offline Member
    Join Date
    Oct 2014
    Posts
    9
    Rep Power
    0

    Default Help with these beginner JAVA lines of code

    I need to write a JAVA program and algorithm that writes the numbers from 1 to 1000. Then I ned to write another one that writes the numbers from 1 to 1000, but 5 by 5. ( example 5,10,15,20,25,30)


    Its for a class, can someone help me out.

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

    Default Re: Help with these beginner JAVA lines of code

    You need to try it yourself first. Then post your code here between
    code tags [code][/code] and we will help.

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

  3. #3
    Nybbler is offline Member
    Join Date
    Feb 2014
    Posts
    7
    Rep Power
    0

    Default Re: Help with these beginner JAVA lines of code

    I'll give you a hint: Use a loop construct.
    Otherwise, you really need to make an effort yourself before asking for help.

  4. #4
    xlactyu is offline Member
    Join Date
    Oct 2014
    Posts
    9
    Rep Power
    0

    Default Re: Help with these beginner JAVA lines of code

    Quote Originally Posted by Nybbler View Post
    I'll give you a hint: Use a loop construct.
    Otherwise, you really need to make an effort yourself before asking for help.
    Thank you for the hint, I did it with a for loop.
    Java Code:
    import java.util.Scanner;
        
    class counting
    {
       public static void main(String [] args)
       {
       
          Scanner input = new Scanner (System.in);
       
          int start;
       
          for (start=0; start <= 1000;start = start + 5){
             System.out.println(start);
          }
       }
    }
    Last edited by xlactyu; 10-10-2014 at 07:51 PM.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Help with these beginner JAVA lines of code

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Help with these beginner JAVA lines of code

    Quote Originally Posted by xlactyu View Post
    Thank you for the hint, I did it with a for loop.
    Java Code:
    import java.util.Scanner;
        
    class counting
    {
       public static void main(String [] args)
       {
       
          Scanner input = new Scanner (System.in);
       
          int start;
       
          for (start=0; start <= 1000;start = start + 5){
             System.out.println(start);
          }
       }
    }
    Well done; a few nitpicks though: your program prints a zero as the first number; do you want that? (your original post indicated that 5 should be the first number). Second nitpick: if you don't need variable start anymore after the loop has finished, change lines #10 ... #12 to:

    Java Code:
    for (int start= 0; start <= 1000; start= start+5) {
    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. need help writing code for a java program, im beginner
    By kittykat0953 in forum New To Java
    Replies: 7
    Last Post: 01-29-2014, 07:08 PM
  2. java code help please beginner
    By aaden1 in forum New To Java
    Replies: 5
    Last Post: 10-29-2012, 07:03 PM
  3. How to jump between lines of code?
    By thyks in forum New To Java
    Replies: 7
    Last Post: 06-25-2012, 08:55 AM
  4. Replies: 8
    Last Post: 06-06-2011, 03:27 AM
  5. Unify these 3 lines of code
    By ulykidjoe in forum Advanced Java
    Replies: 4
    Last Post: 07-13-2007, 02:15 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
  •