Solved

fizzArray  challenge

Posted on 2016-08-03
1
47 Views
Last Modified: 2016-08-03
Hi,

I am working on below challenge

http://codingbat.com/prob/p180920

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 until size

I wrote my code as below



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

Open in new window


public class FizzArrayEx {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("fizzArray is-->"+fizzArray(4).toString());

	}

	
	public static int[] fizzArray(int n) {
		  int size=n;
		  int[] ar=new int[size];
		  for(int i=0;i<n;i++){
		    ar[i]=i;
		  }
		  
		  return ar;
		}

}

Open in new window

i got below output
fizzArray is-->[I@15db9742

I am not seeing any test results when i ran above code

How to improve my design, approach, code? please advise
0
Comment
Question by:gudii9
1 Comment
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 41741687
The output you are seeing is the default way Java converts an Array to a String. What you might want to do is replace line 5 of the above code with this...

		System.out.println("fizzArray is-->"+Arrays.toString(fizzArray(4)));

Open in new window


It uses a separate utility class (java.util.Arrays) to convert the array (and it's contents) into a String for you.

BTW, I don't see anything wrong with your design or code, it works just fine in the codingbat site.

The only thing I would do differently is remove line 11, and just the variable n in line 12 (rather than size).
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

757 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

23 Experts available now in Live!

Get 1:1 Help Now