Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

fizzArray2 challenge

Hi,

I am working on below challenge

http://codingbat.com/prob/p178353

Psedo code description of approach :
1. identify size of array.
2. create new empty array of above size
3. keep putting each element of array with above values in string form until size

I wrote my code as below


public String[] fizzArray2(int n) {
 
  
		 // int size=n;
		  String[] ar=new String[n];
		  for(int i=0;i<n;i++){
		    ar[i]="i";
		  }
		  
		  return ar;
		
}

Open in new window



I am not passing all tests
Expected      Run            
fizzArray2(4) → ["0", "1", "2", "3"]      ["i", "i", "i", "i"]      X      
fizzArray2(10) → ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]      ["i", "i", "i", "i", "i", "i", "i", "i", "i", "i"]      X      
fizzArray2(2) → ["0", "1"]      ["i", "i"]      X      
fizzArray2(1) → ["0"]      ["i"]      X      
fizzArray2(0) → []      []      OK      
fizzArray2(7) → ["0", "1", "2", "3", "4", "5", "6"]      ["i", "i", "i", "i", "i", "i", "i"]      X      
fizzArray2(9) → ["0", "1", "2", "3", "4", "5", "6", "7", "8"]      ["i", "i", "i", "i", "i", "i", "i", "i", "i"]      X      
fizzArray2(11) → ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]      ["i", "i", "i", "i", "i", "i", "i", "i", "i", "i", "i"]      X      
other tests
X

How to improve my design, approach, code? please advise
0
gudii9
Asked:
gudii9
1 Solution
 
Hammadh Abdul RahmanCommented:
Currently the character "i" is being printed. To print the value of variable i, change line 7 as shown below.

ar[i]=String.valueOf(i);

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now