7 Replies - 3710 Views - Last Post: 14 July 2017 - 08:35 AM Rate Topic: -----

#1 Joescript100  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 28-December 16

I need help with this Array Question

Posted 28 December 2016 - 03:19 AM

Question: Write a program that stores the first 400 numbers that are multiples of 13 in an array.

Here is My answer:

public class ArrayProgram{

public static void main(String[]args){

for(int x=1;x<400;x++){int multiArray[]={13*x};
if(multArray[0]<400)
{System.out.println(multArray[0]);}

else{System.out.println("stop");break;}
}
}
}



I know I am syntactically correct but I hope it doesn't give me a semantic error. Because after running it did what I thought the question was asking for.

Please just review and let me know if I am wrong.

If you see anytypo in syntax please ignore because I used my Android phone to type it out and wasn't easy as It was in eclipse.

Lastly please I need a pal to hook up with in Java and python. I am a Nigerian self-taught newbie programmer . Here is my whatsapp number +2348031394935 thanks.



Sent from my TECNO_P5_PLUS using Tapatalk

This post has been edited by andrewsw: 28 December 2016 - 03:22 AM
Reason for edit:: added missing [code][/code] tags


Is This A Good Question/Topic? 0
  • +

Replies To: I need help with this Array Question

#2 andrewsw  Icon User is offline

  • I'd like to return this printer
  • member icon

Reputation: 6322
  • View blog
  • Posts: 25,418
  • Joined: 12-December 12

Re: I need help with this Array Question

Posted 28 December 2016 - 03:23 AM

Do not post questions in the Tutorials section. Question moved to Java forum.

Also wrap your code in code tags, it shows you how to do this directly in the area where you type your post.
Was This Post Helpful? 0
  • +
  • -

#3 xiledcore  Icon User is offline

  • D.I.C Head

Reputation: 23
  • View blog
  • Posts: 62
  • Joined: 20-March 16

Re: I need help with this Array Question

Posted 28 December 2016 - 07:10 AM

I'm a little confused. If the program did what the question was asking for, doesn't that answer your own question?

How did you test the program?
Was This Post Helpful? 0
  • +
  • -

#4 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2493
  • View blog
  • Posts: 3,930
  • Joined: 21-June 11

Re: I need help with this Array Question

Posted 28 December 2016 - 07:33 AM

You're supposed to create one array, holding 400 elements. You're creating 400 arrays, each holding one element.

PS:

View PostJoescript100, on 28 December 2016 - 11:19 AM, said:

If you see anytypo in syntax please ignore because I used my Android phone to type it out and wasn't easy as It was in eclipse.


Please don't do that. You say to ignore syntax errors, but what about semantic errors? How do we know whether any problem in the code exists in the real code or whether you created it when re-typing the code? Often this kind of thing leads to an endlessly frustrating back-and-forth of "You did this and that wrong" - "No, I didn't I just retyped it wrong" ad nauseam. Plus the formatting on your code is horrible, making your code hard to read. I assume that has also been introduced by your re-typing and your original code is properly formatted.

So in the future, please copy your real code instead of retyping. And if you can't right now, then wait until you can. I mean, you won't be able to implement and advice we give you until you're in front of a computer (with your code on it) anyway, right? So you might as well wait to ask the question until then.
Was This Post Helpful? 0
  • +
  • -

#5 rajeshjangra  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-May 17

Re: I need help with this Array Question

Posted 19 May 2017 - 06:30 AM

IntStream.rangeClosed(1, 400).forEach(x -> System.out.println(x * 13));

Was This Post Helpful? 0
  • +
  • -

#6 Atspulgs  Icon User is offline

  • D.I.C Addict

Reputation: 89
  • View blog
  • Posts: 507
  • Joined: 29-July 09

Re: I need help with this Array Question

Posted 19 May 2017 - 07:30 AM

Is the problem to generate and store first 400 multiples of 13 or to generate and store all multiples of 13 that are smaller than 400 ?

I ask this cause the description of the problem you give us "verbally" states that you have to generate and store first 400 multiples of 13 ( or so I understood it ). However in the actual implementation you are checking each value you generate - if it is lower than 400 - else stop the generation. This will clearly generate much less than 400 values.

Also you are not really storing the values either. Once the for loop exits, the generated data becomes inaccessible. All you've essentially done is printed them values.

This post has been edited by Atspulgs: 19 May 2017 - 07:30 AM

Was This Post Helpful? 0
  • +
  • -

#7 Atspulgs  Icon User is offline

  • D.I.C Addict

Reputation: 89
  • View blog
  • Posts: 507
  • Joined: 29-July 09

Re: I need help with this Array Question

Posted 19 May 2017 - 07:48 AM

View Postrajeshjangra, on 19 May 2017 - 07:30 AM, said:

IntStream.rangeClosed(1, 400).forEach(x -> System.out.println(x * 13));


I apologies for being picky, but isn't your solution essentially the same as this?
for(int i = 13; i <= 400*13; i += 13)
    System.out.println(i);


This post has been edited by Atspulgs: 19 May 2017 - 07:50 AM

Was This Post Helpful? 0
  • +
  • -

#8 BrainlessThinker  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 14-July 17

Re: I need help with this Array Question

Posted 14 July 2017 - 08:35 AM

don't know that your program is doing what the question is asking let me help you


int[] array;
int num;
for(int i=1; i<=400; i++);
{
for(int j=1; j<=400; j++);
{
if(i%13 == 0)
{
    num = i;
    array[j] = num;

}

    System.out.println(array[j]);
  } 

}



hope it helps if not then please tell
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1