![]() |
Java-Beginer
(a) Create a new class Test_Array that has the following 3 class methods:
(i) fillArray() takes an integer array as an argument. It allows user to fill-up values in this array by using a for loop and a series of dialog boxes. public static void fillArray(int[] value) { String valueInput; String length; length = OUDialog.request("How much Value to store?", "1"); value = new int[Integer.parseInt(length)]; for(int i=0; i<value.length; i++) { valueInput=OUDialog.request("Please insert an integer value", "0"); value[i]=Integer.parseInt(valueInput); } } int[] a; Test_Array.fillArray(a); when executing the array a is stayed null and is not affected..... what is mistake? pleeeeeeeeeeeeeeeeeeeeeeease help me :( |
Grammar Nazis, Do your job.
|
hey 7anzala I'm new to the java language but i tried to see what's the problem in this project I am not familiar with the command you are using for the dialog box(which i think is your problem) but here is my way to wright this project :
The class : import javax.swing.JOptionPane; public class Test_Array { public static void fillArray(int[] value){ String valueInput; String length; length = JOptionPane.showInputDialog("how much value to store ?"); value = new int[Integer.parseInt(length)]; for(int i=0; i<value.length; i++) { valueInput = JOptionPane.showInputDialog("please insert an integer value"); value[i]=Integer.parseInt(valueInput); } for (int i=0;i<value.length;i++){ System.out.println("value ["+i+"] = "+value[i]); } } } The main class : public class Main { public static void main(String[] args) { int[] a = null ; Test_Array.fillArray(a); } } PS: the last for loop is to display the affected values in the array. good luck hope i helped you :)....... |
mmm yes i made a difference :D 10x
|
| All times are GMT +1. The time now is 12:38 AM. |
Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger