i need to create a program that asks the user for an array and then
asks the user to fill in the slots of the array but i have to do it
in a method can any 1 help i can post the question if it will help
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
i need to create a program that asks the user for an array and then
asks the user to fill in the slots of the array but i have to do it
in a method can any 1 help i can post the question if it will help
What have you tried? Where are you stuck?
If you don't understand my answer, don't ignore it, ask a question.
Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.
Please give your threads useful/meaningful titles. Title changed to be more useful. (Which messed up your link in the chat box.)
public class Ex6_02 { public static void main(String[] args) { String ans = JOptionPane.showInputDialog("give me a length"); int Lgth = Integer.parseInt(ans); int[] int1 = new int[Lgth]; int [] arrint = createEmptyIntArray(int1); System.out.println(arrint); /* String [] arrstr = createEmptyStringArray(); boolean [] arrboo = createEmptyBooleanArray();*/ for (int i = 0; i < arrint.length; i++) { System.out.println(int1[i]); } /* for (int i = 0; i < arrstr.length; i++) { } for (int i = 0; i < arrboo.length; i++) { }*/ } /* private static String[] createEmptyStringArray() { } private static boolean[] createEmptyBooleanArray() { }*/ private static int[] createEmptyIntArray(int[] int1) { String ans = JOptionPane.showInputDialog("give me a number"); int Lgth = Integer.parseInt(ans); int[] arr2 = new int [int1.length]; for (int i = 0; i < int1.length; i++) { if (int1.length == i) { arr2[i] = int1[i]; } } return arr2; }
thats what i go so farm but then i try some thing else it freaks out
If there are error messages, copy the full text and paste it here. Plus the code that caused the error.it freaks out
If you don't understand my answer, don't ignore it, ask a question.
ok yea i know that but what i need to do is make it so that it asks for a number for every open slot in the array and i cant think of how to do that
Use a for loop that goes through the array, when there is an open slot ask the user for a value to put in that slot, read the value and put it in the open slot.
If you don't understand my answer, don't ignore it, ask a question.