Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Initializing my long array with prime numbers  RSS feed

 
Greenhorn
Posts: 25
1
Android
  • Mark post as helpful
  • send pies
  • Report post to moderator

     Hi, I'm having a hard time figuring out how to initialize my array with prime numbers using the method I created. I keep getting this error: "incompatible types: possible lossy conversion from long to int" for the line
primes[number] = number;
How do I fix this? Here is what I wrote:

 
Marshal
Posts: 5926
411
BSD
  • Mark post as helpful
  • send pies
  • Report post to moderator
Welcome to the Ranch.

You probably know that array indices start counting from zero. Looking to your code, you start filling an array from position 2 (at best), which is the 3rd element in an array - probably it isn't what you want.

You correctly identified that you need a method which defines if number is a prime one. Is that method correct? Have you tested, verified that?

Going back to the loop within the main method, in order to fill in an array fully, you need to iterate over each its element position, that means starting from index 0 each time increasing it by 1, until condition 'index < primes.length' fails.
 
Bartender
Posts: 4519
50
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
This is a continuation of this thread https://coderanch.com/t/672713/java/Writing-static-method-calculates-number
 
author
Sheriff
Posts: 23568
138
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Report post to moderator
Yeah. Let's stay with the original topic.

Henry
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!