0
fill an array of size n with the first n ugly numbers
3 Answers
0
Yes it is a question.
0
import java.io.*; class array { int [] arr; int n; void input()throws IOException { DataInputStream in=new DataInputStream(System.in); System.out.println("enter value of n"); n=Integer.parseInt(in.readLine()); arr=new int[n]; } int check(int x) { if(x%2==0||x%3==0||x%5==0) return 1; else return 0; } public static void main(String a[])throws IOException { DataInputStream in=new DataInputStream(System.in); input(); int c=0; int no=1; for(int i=0;i<=n;) { int r=check(no); if(r==1) { arr[i]=no; c++; no++; i++; } } System.out.print("the array:"); for(int i=0;i<=n;i++) { System.out.print(arr[i]+" "); } } }
0
This was my attempt. Can you please spot the error.