Results 1 to 10 of 10
  1. #1
    The James is offline Member
    Join Date
    Apr 2017
    Posts
    8
    Rep Power
    0

    Default Display multiples of 7

    Write a program that displays all the multiples of 7 that occur between 1 and 494 in rows of 7 numbers each.
    The output looks like this:-
    7 14 21 28 35 42 49
    56 63 70 77 84 91 98
    105 112 119 126 133 140 147
    154 161 168 175 182 189 196
    203 210 217 224 231 238 245
    252 259 266 273 280 287 294
    301 308 315 322 329 336 343
    350 357 364 371 378 385 392
    399 406 413 420 427 434 441
    448 455 462 469 476 483 490

  2. #2
    The James is offline Member
    Join Date
    Apr 2017
    Posts
    8
    Rep Power
    0

    Default Java PROGRAM, how do you display multiples to a pacific number

    Write a program that displays all the multiples of 7 that occur between 1 and 494 in rows of 7 numbers each.
    The output looks like this:-
    7 14 21 28 35 42 49
    56 63 70 77 84 91 98
    105 112 119 126 133 140 147
    154 161 168 175 182 189 196
    203 210 217 224 231 238 245
    252 259 266 273 280 287 294
    301 308 315 322 329 336 343
    350 357 364 371 378 385 392
    399 406 413 420 427 434 441
    448 455 462 469 476 483 490

  3. #3
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default re: Display multiples of 7

    When you have no idea how to start, it's time to turn off the computer, grab a pen and paper and start doing it by hand, on paper, the old school way.

    This exercise actually has two parts:
    1) Getting from 0 to 494 in steps of 7
    2) Printing them out in rows of 7 numbers

    For #1, there are multiple ways of doing this, but think about a loop, starting at 7, and keep multiplying that with 1, then 2, then 3, then 4, until the number you get is larger than 494.
    For #2, you can actually use the multiplier from #1. When that reaches a number divisible by 7, it's the end of the row and you should go to the next line. (Hint: Java has an operator to calculate the remainder of a division)
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  4. #4
    nengkya is offline Member
    Join Date
    Apr 2017
    Posts
    2
    Rep Power
    0

    Default Re: Java PROGRAM, how do you display multiples to a pacific number

    for i in range(1,494,7):

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

    Default Re: Display multiples of 7

    Duplicate threads merged. Please do NOT start multiple threads on same topic.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    The James is offline Member
    Join Date
    Apr 2017
    Posts
    8
    Rep Power
    0

    Default Re: Display multiples of 7

    YEAH no worries Norm, it was an error.

  7. #7
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: Java PROGRAM, how do you display multiples to a pacific number

    Quote Originally Posted by nengkya View Post
    for i in range(1,494,7):
    Congratulations. You managed to post a piece of Python code on a Java forum. Even though there is a Java statement that does the same, it's extremely confusing for someone who just started Java.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  8. #8
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: Display multiples of 7

    Quote Originally Posted by raghusomineni View Post
    Hi, code is below.
    Can a moderator please delete this shitty code and give raghu a nice official warning?

    DO. NOT. SPOONFEED. CODE. Why? Cos any random student will learn nothing of the exercise his teacher gave him, he will hand this in as code of his own and he will pass his Computer Science classes not because he's smart, but because you posted random solutions to it. He then ends up working in IT, hopefully becoming YOUR colleague. But he stinks cos all he does is copy/paste from you and/or the first answer on StackOverflow. He will get fired because he can't program for jack shit. He will divorce his wife, not allowed to see his kids, and has to take his scruffy dog to live under the bridge. He will be drinking and doing drugs and dies ill-ridden before he turns 40. All because of you.

    Or maybe not. Anyway, let this guy finish his exercise on his own.

    Edit: Just for clarity: user raghusomineni posted some code that solved OP's problem. Apparently a moderator has waved the delete-stick and the post is gone. (Without the original post, mine doesn't make much sense :))
    Last edited by SurfMan; 04-06-2017 at 09:43 AM.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  9. #9
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    5

    Default Re: Display multiples of 7

    So, if you want a good time with your dog, post a question on java-forums.org hoping that sb will spoon feed you. Makes sense to me.

  10. #10
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: Display multiples of 7

    Quote Originally Posted by benji2505 View Post
    So, if you want a good time with your dog, post a question on java-forums.org hoping that sb will spoon feed you. Makes sense to me.
    You have been around here long enough to see people try that all the time.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Checking Multiples from arguments?
    By kadanakanz in forum New To Java
    Replies: 1
    Last Post: 05-16-2013, 09:07 AM
  2. replaceAll() multiples- looking for elegant solution
    By Redefine12 in forum New To Java
    Replies: 5
    Last Post: 07-21-2012, 08:14 AM
  3. Print Odd Multiples of 3
    By mp3_1 in forum New To Java
    Replies: 9
    Last Post: 11-22-2011, 09:09 PM
  4. Multiples Integers from a String
    By AndrewM16921 in forum New To Java
    Replies: 3
    Last Post: 04-01-2009, 12:00 AM

Posting Permissions

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