BSc Computer Science - “Java” (SE2JA11) Meta-Programming in Java: Reflection
Computer Java
-
Upload
tanvi-kamani -
Category
Documents
-
view
237 -
download
0
description
Transcript of Computer Java
1D ARRAY
FREQUENCYQUESTION:A class PrimeFac contains an array of 50 integers. Some of the members of the class are given below:Class name : PrimeFacData members/instance variables : num[ ] : array to store integersfreq[ ] : array to store the frequency of prime factors of numbers.Member functions :PrimeFac( ) : constructor to initialize array elements to 0void enter( ) : to enter values into array num[ ]void frefac( ) : to determine the frequency of prime factors of the numbers stored . in num[ ]and assign it to freq[ ]void disp( ) : to display both the arraySpecify the class PrimeFac giving the details of constructors, void enter ( ),void refac( ) and void disp( ).
PROGRAM:import java.io.*;public class PrimeFac{ int num[]=new int[5]; int freq[]=new int[5]; PrimeFac() { for(int i=0;i < 5;i++) { num[i]=0; freq[i]=0; } } void input()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); for(int i=0;i < 5;i++) { System.out.println("Enter a Number"); num[i]=Integer.parseInt(br.readLine()); } } void frefac() {int i,j,k,c;for(i=0;i < 5;i++){ c=0; for(j=1;j