473,418 Members | 2,119 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

ArrayIndexOutOfBoundsException ( Partition )

I was browsing the web for examples on how to partition in Java. I've got to this website that has a detailed example about Partitioning so I've tried to run it on my JCreator Pro.

I've only got one error, but I've tried all I can do to fix it ( Put BufferedReader, import java.io.*, throws IOException ), and It still wouldn't work.

Here's the Error:
Expand|Select|Wrap|Line Numbers
  1. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
  2.     at Partition.main(Partition.java:19)
Here's the Code:
Expand|Select|Wrap|Line Numbers
  1. public class Partition { 
  2.  
  3.     public static void partition(int n) {
  4.         partition(n, n, "");
  5.     }
  6.     public static void partition(int n, int max, String prefix) {
  7.         if (n == 0) {
  8.             StdOut.println(prefix);
  9.             return;
  10.         }
  11.  
  12.         for (int i = Math.min(max, n); i >= 1; i--) {
  13.             partition(n-i, i, prefix + " " + i);
  14.         }
  15.     }
  16.  
  17.  
  18.     public static void main(String[] args) { 
  19.         int N = Integer.parseInt(args[0]);
  20.         partition(N);
  21.     }
  22.  
  23. }
  24.  
Thank You!
Oct 17 '10 #1
1 2204
Nepomuk
3,112 Expert 2GB
The exception is thrown here:
Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args) { 
  2.    int N = Integer.parseInt(args[0]);
  3.    partition(N);
  4. }
which probably means, you're calling the program without any arguments. I'm not quite sure how to call it with arguments in JCreator Pro (though I'm sure you can find that), but in any case you should catch that mistake by changing it to something like
Expand|Select|Wrap|Line Numbers
  1. public static void main(String[] args) { 
  2.    if(args.length > 0) {
  3.       int N = Integer.parseInt(args[0]);
  4.       partition(N);
  5.    }
  6.    else
  7.       System.out.println("Partition called without any arguments.");
  8. }
Greetings,
Nepomuk
Oct 19 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: CM | last post by:
Hi, when i want connect me in my BD with a JSP (with this simple code), this exception is throw. Thank's for ur help Mathieu CODE of my JSP ---------------------
1
by: Mark Dengler | last post by:
I am trying to write a C# backend program that will handle the database maintenance that I would otherwise have to do via Microsoft's Analysis Services front end GUI Wizards. Currently I am having...
2
by: David Stevenson | last post by:
Programs from: Sheng Liang, The Java Native Interface, Programmer's Guide and Specification, The Java Series, (c) 1999, pp. 38-39. I thought I copied the program pretty exactly, but I don't know...
6
by: ganesh.m | last post by:
Hi, I am new to DB2. I am getting this error while loading the DB2Driver. I don't have any idea about where i might have gone wrong. please help me. Below is the stack trace. Stack Trace:...
31
by: ivannavi | last post by:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { String Temp = jComboBox1.getSelectedItem().toString(); ...
1
by: Laurence | last post by:
Hi folks, As I konw: database partition (aka data partition?), the database can span multiple machines; table partition, the data within a table can seperate by certain condition. How about...
22
oll3i
by: oll3i | last post by:
i get Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2 at Producent.main(producent.java:605) when i run it from bat @start "Supply Chain Management-Producer to...
0
by: Vinod Sadanandan | last post by:
Table Partition Performance analysis ============================================ Collection of Statistics for Cost-Based Optimization/DBMS_STATS vs. ANALYZE The cost-based approach relies on...
0
debasisdas
by: debasisdas | last post by:
SAMPLE CODE TO CREATE SUB PARTITIONS ======================================= RANGE-HASH-9i ------------------------- CREATE TABLE SUBPART ( ID NUMBER(10) PRIMARY KEY, NAME VARCHAR2(20) )
2
by: David Rothabuer | last post by:
I work with an integration engine that is java based. All my scripting is javascripting and I've run into a problem that I can't find a solution to. I am getting this error when I attempt to read...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.