Solved

fizzArray2 challenge

Posted on 2016-08-03
1
123 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

This is about my first experience with programming Arduino.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

623 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