Solved

fizzArray2 challenge

Posted on 2016-08-03
1
78 Views
Last Modified: 2016-08-03
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
Comment
Question by:gudii9
1 Comment
 
LVL 4

Accepted Solution

by:
Hammadh Abdul Rahman earned 500 total points
ID: 41741693
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jar file executable 12 51
SHA2 certs for IIS AND Java? 2 81
null output 3 24
some keys in my laptop is not working. any suggestion 6 25
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question