Solved

fizzArray2 challenge

Posted on 2016-08-03
1
102 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java imports not found 4 51
moto 4g phone enable finger print 4 47
Why use this lambda? 12 64
Documenting and diagramming code flow within a VBA Excel project 5 52
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…

733 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