Solved

fizzArray2 challenge

Posted on 2016-08-03
1
55 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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
json example 39 110
wordappend challenge 8 83
Microsoft C++ code failing in executable that worked 9 50
Device same like our heart 12 43
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now