The Artima Developer Community
Sponsored Link

Java Answers Forum
How do i rectify this?!

1 reply on 1 page. Most recent reply: Mar 13, 2006 3:49 AM by nabakumar

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
zeba takmeel

Posts: 10
Nickname: zeba
Registered: Mar, 2006

How do i rectify this?! Posted: Mar 12, 2006 9:13 PM
Reply to this message Reply
Advertisement
im facing a problem with a part of a program..
if i have a program say..

class A
{
int x;
String y[];
A(int x,String y[])
{
this.x=x;
for(int i=0;i<x;i++)
{
this.y=y;
}
}
}

public class B
{
public static void main(String args[])
{
int a;
//get value of a

String b[]=new String[a];
//use for loop and get values in b[]
A myA=new A(a,b);
}
}

now i know im going wrong somewhere cuz once my program reaches the constructor part, an exception is thrown..but i need to pass this array as a parameter as well!!..how do i rectify this??


nabakumar

Posts: 23
Nickname: nkmeitei
Registered: Jun, 2005

Re: How do i rectify this?! Posted: Mar 13, 2006 3:49 AM
Reply to this message Reply
Check out whether this solves ur problem....

class A{
int x;
String y[] ;
public A(int x,String y[]){
this.x=x;
this.y = new String[x];
for(int i=0;i<x;i++){
this.y=y;
}
}
}

public class B{
public static void main(String args[]){
int a=2;
//get value of a

String b[]=new String[a];
//use for loop and get values in b[]
try{
A myA=new A(a,b);
}catch(Exception e){
e.printStackTrace();
}
System.out.println("Done");
}
}

Flat View: This topic has 1 reply on 1 page
Topic: Is this task hard for a beginner to accomplish in 1 day? Previous Topic   Next Topic Topic: How to make an internal frame unmovable?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use