Answer the question
In order to leave comments, you need to log in
How to create an array from a large number of elements not manually?
There is a program that displays a large number of numbers on the screen. How can you create an array from these numbers so as not to manually enter each number?
This program displays numbers 1) less than 1000; 2) a multiple of three; 3) a multiple of five. From all these numbers, you need to create an array with type int .. Help, I can’t figure out how to do this
package javaapp1;
class JavaApp1 {
public static void main(String args[]){
int i;
for(i =0; i<=1000; i++){
if((i%3==0) & (i%5==0)){
System.out.println(i);
}
}
}
Answer the question
In order to leave comments, you need to log in
int[] a = new int[67];
for (int i = 0, n = 0; i <= 1000; i++) {
if ((i % 3 == 0) && (i % 5 == 0)) {
a[n++] = i;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question