1Numbers -- FINRA
2Write a method which prints out the numbers from 1 to 30 but for numbers
3which are a multiple of 3, print "FIN" instead of the number and for numbers
4which are a multiple of 5, print "RA" instead of the number. for numbers
5which are a multiple of both 3 and 5, print "FINRA" instead of the number.
6
7 Solution 1:
8public static void FINRA() {
9String result = "";
10for(int i=1; i <= 30; i++) {
11if(i % 5==0 && i %3 ==0)
12result += "FINRA ";
13else if(i%5 == 0)
14result += "RA ";
15else if(i%3==0)
16result+="FIN ";
17else
18result += i+" ";
19}
20System.out.println(result);
21}
22
23Solution 2:
24public static void FINRA() {
25String result = "";
26for(int i=1; i <= 30; i++) {
27result += (i % 5 ==0 && i %3 ==0)? "FINRA " : (i%5 == 0) ? "RA "
28:(i%3 == 0) ? "FIN " : i+" ";
29}
30System.out.println(result);
31}
32
33Solution 3:
34public static void FINRA() {
35String[] myarr= new String[30];
36
37for( int i=0; i <= 29; i++ )
38myarr[i] = ""+(i+1);
39
40for(int j=0; j<myarr.length; j++)
41if(Integer.valueOf(myarr[j])%3==0 && new Integer(myarr[j])%5==0)
42myarr[j]="FINRA";
43else if (Integer.valueOf(myarr[j])%3==0)
44myarr[j]="FIN";
45else if (Integer.valueOf(myarr[j])%5==0)
46myarr[j]="RA";
47
48System.out.println(Arrays.toString(myarr));
49}