Randomizing the Array Size
Hello,
How do make a random number that is between 20 to 50, and then make the random number to be the size of that array.
Also My assignment is to make a Binary Search Lab.
What does the Word "probe" mean?
Example:
What entry? 14
status: found at index 6 after 4 probes.
Now what exactly does probe means, i dont understand.
How do make a random number that is between 20 to 50,You can use java.util.Random:
http://java.sun.com/j2se/1.5.0/docs/api/java/util/Random.html
and then make the random number to be the size of
that array.
Do you know how to create an array? If you do, then just create the array when you have generated the random number. If you don't, then read this:
http://java.sun.com/docs/books/tutorial/java/data/arraybasics.html
Also My assignment is to make a Binary Search Lab.
What does the Word "probe" mean?
Example:
What entry? 14
status: found at index 6 after 4 probes.Maybe it means "searches"? But really, if you're not sure what the assignment means you should ask your teacher for clarification.
Similar Messages
-
What can I do if I want to unlimited the array size
Hi all
I am new in Java, I would like to create a array in MyObject type. (MyObject is the object i created) But I don't want to limited the array size, Any other ways can do this?
Myobject[] myob;
myob = new Myobject[10];
Thanks
Regards,
KnUse ArrayList or Vector
example
Vector myarray = new Vector();
myarray.add(myObject);
to get the object back
myObject = (MyObject) mayarray.get(index); -
Adding rows to a datatable, depending on the array size
I have a situation like this:
In my managed bean, i have an array of size 5.
In the faces jsp page, I have a datatable, which refers to this array. I need to display five rows in the datatable. How do I do this?
<h:column>
<f:facet name="header">
<h:outputText styleClass="outputText" value="#{lbl.tripDateStart}" id="tripDateStartLbl"></h:outputText>
</f:facet>
<h:inputText styleClass="inputText" id="tripDateStart" size="11"
value="#{parmHandler.model.tripDateStartArray}"
required="true">
</h:inputText>
<h:message styleClass="message" id="tripDateStartMsg" for="tripDateStart"></h:message>
</h:column>This displays only one row.
Is there a need for iteration? If so, how do I do it?On you <h:dataTable> the 'value' attribute should point to the array on your backing bean, use the 'var' attribute on the <h:column>
<h:dataTable value="#{parmHandler.model.tripDateStartArray}" var="dataStart">
<h:column>
<f:facet name="header">
<h:outputText styleClass="outputText" value="#{lbl.tripDateStart}" id="tripDateStartLbl"></h:outputText>
</f:facet>
<h:inputText styleClass="inputText" id="tripDateStart" size="11"
value="#{dateStart}"
required="true">
</h:inputText>
<h:message styleClass="message" id="tripDateStartMsg" for="tripDateStart"></h:message>
</h:column>
</h:dataTable> -
Hello!
Now we have the following problem: We have an array of a cluster and in this cluster we have an array. We need to compare the length between the array named "sampelnr"...
If they are not equal length we need to get the "signalname" from the array which is the smallest. The "Array" could be of different length from time to time... does anyone have any tip for us?
See the attached VI. Best regards and thank you!
Attachments:
arrayquestion.vi 18 KBThere will be more to your problem, because you don't tell what the output should be if:
all elements are the same lenght
more than one array has a smallest size (e.g. if we have the following lenghts [4,4,5,6,7], the first two have smallest size. Do you want both names?).
Attached is a small example that shows two possible interpretations, pick the more suitable for your case:
In the upper (blue) part, it assumes that there is only one "smallest" array.
In the lower (red) part, it shows how to get all names where the array is equal to the smallest size.Message Edited by altenbach on 04-18-2005 08:55 AM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
arrayquestionMODIFIED.vi 48 KB -
Hi,
below is my sample code
class test
int sample[][]=new int[10][10];
int rows=0,k=0;
int columns=0;
public void meth()
rows=9;
columns=9;
}//end of meth()
public meth_2()
for (int i=0;i<rows;i++)
for(int j=0;j<columns;j++)
sample[i][j]=k;
k++;
for (int i=0;i<rows;i++)
for(int j=0;j<columns;j++)
System.out.println(sample[i][j]);
}//end of meth_2()
public int[][] getList()
return sample;
}//end of classNow that my question is, i need to set the size of array sample[][] to sample[rows+1][columns+1].. but to do so, 'rows' and 'columns' values will only be generated upon the execution of method meth() . I need sample[][] array to be declared right after the class begins. The values that are returned from sample[][] array through that getList() method is been used in another class.. So how do i set the size of sample[][] array to
int sample[][] = new int[rows+1][columns+1];Any response is highly appreciable.
Thanks in advance
Edited by: netbeans2eclipse on Sep 14, 2008 1:20 PMIt seems you answered your question yourself ;-)
Just split this:
int sample[][] = new int[rows+1][columns+1];in two parts.
Declaration:
int sample[][];and instantiation in meth() or meth_2():
sample = new int[rows+1][columns+1]; -
import java.util.*;
public class Main {
* @param args the command line arguments
private static void bubbleSort(int[] x) {
int n = x.length;
boolean doMore = true;
while (doMore) {
n--;
doMore = false;
for (int i=0; i<n; i++) {
if (x[i] > x[i+1]) {
int temp = x; x[i] = x[i+1]; x[i+1] = temp;
doMore = true;
public static void main(String[] args) {
while(true){
System.out.println("What do you want to perform choose :\n 1. Searching\n 2. Sorting\n 3. Exit\n ");
Scanner input = new Scanner(System.in);
switch(input.nextInt()){
case 1 : System.out.println("1. Linear Searching\n2. Binary Searching\n");
switch(input.nextInt()){
case 1 :System.out.println("Linear Search: ");
continue;
case 2 :System.out.println("Binary Search: ");
break;
continue;
case 2 : System.out.println("Please provide the size of the array between 5 to 30; ");
int arrays = input.nextInt();
System.out.println("If you want to supply the number between 1 to 100 press 1,or\n2 to generate it ramdomly: ");
switch (input.nextInt()){
case 1: int num = 0;
int[] arrSize = new int[30];
for(int i = 0; i <=arrSize.length; i++){
arrSize[i] = num;
System.out.println("Please enter number on index"+i+":");
num=input.nextInt();
break;
case 2: int[] arr = new int[30];
Random random = new Random();
for (int idx = 1; idx <= 30; ++idx){
int randomInt = random.nextInt(100);
arr[idx - 1] = randomInt;
System.out.println(Arrays.toString(arr));
System.out.println("\n");
System.out.println("What Sorting algorithm you want to ferform?\n1. Bubble Sorting \n2. Selection Sorting\n3. Insertion\n");
switch (input.nextInt()){
case 1 ://code to call bubble sort method
break;
continue;
//continue; //starts the loop again
case 3 : System.exit(0);
break; //exists the loop
default: System.out.println(input.nextInt()+ " is not a valid charachter , please try again");
}//end of while loop
}Sorry im new to this,i have a code there im now developing sorting algo. in my code the user provide a size of the array between 5 to 30 then the user will choose if he/she wants to supply the numbers between 1to100 or these are generated randomly. My problem is that if the user difine the array size, then after the array size given it will ends the loop up to 30. all i want is if the user difine array size 5 only 5 index will prompt. please help im also trying here any advise?
Edited by: limuh on Aug 25, 2008 4:20 AMthanks for the reply. my code now works on the problem:) but the bubblesort method not performing its task. how can i call the bublesort method to sort my values in the array?
case 2 : System.out.println("Please provide the size of the array between 5 to 30; ");
int num = 0;
int arrays = input.nextInt();
for(int i = 0; i <=arrays; i++){
System.out.println("If you want to supply the number between 1 to 100 press 1,or\n2 to generate it ramdomly: ");
switch (input.nextInt()){
case 1: int[] arrSize = new int[arrays];
for(int i = 0; i <=arrSize.length; i++){
arrSize[i] = num;
System.out.println("Please enter number on index"+i+":");
num=input.nextInt();
break;
case 2: int[] arr = new int[arrays];
Random random = new Random();
for (int idx = 1; idx <= arr.length; ++idx){
int randomInt = random.nextInt(100);
arr[idx - 1] = randomInt;
System.out.println(Arrays.toString(arr));
System.out.println("\n");
System.out.println("What Sorting algorithm you want to ferform?\n1. Bubble Sorting \n2. Selection Sorting\n3. Insertion\n");
switch (input.nextInt()){
case 1 : new Main().bubbleSort(x);
break;
} -
Hello;
I am implementing a stack base on array, and the array size will auto increse by double the array size, if the array size is full, But I got a problem that I do not know how to increse the array size. Could anyone help, please.
Thanks.
import java.lang.*;
import java.util.*;
class Stack {
private Object[] elements;
private int topOfStack;
// constructor
public Stack( int size ) {
elements = new Object[size];
topOfStack = -1;
// insert a new element at the top of the stack
public boolean push( Object x ) {
if ( isFull() )
return false;
elements[++topOfStack] = x;
return true;
// delete the most recently inserted element and return it
public Object pop() {
if ( isEmpty() )
return null;
return elements[topOfStack--];
// return the most recently inserted element
public Object top() {
if ( isEmpty() )
return null;
return elements[topOfStack];
// check if the stack is empty or not
public boolean isEmpty() {
return topOfStack == -1;
// check if the stack is full or not
public boolean isFull() {
return topOfStack == elements.length - 1;
public class StackApp {
public static Random generator;
public static void main( String[] args ) {
Stack stack = new Stack(1);
generator=new Random();
for(int i=0; i<100;i++){
int r = generator.nextInt(100)+1;
stack.push( new Integer(r) );
while( !stack.isEmpty() ) {
Integer integerObject = (Integer)stack.pop();
System.out.print( integerObject.intValue() );
System.out.print( " " );
System.out.println();
}add a private resize method.
this method creates a new array double the size of the old one.
Then you loop over all of the elements in your old array and copy
them into your new array ( you could use System.arrayCopy
rather then perform the loop yourself). They you assign your new
array to elements reference.
private void resize() {
Object[] tmp = new Object[elements.length * 2];
for(int i=0;i<elements.length;i++) {
tmp[i] = elements;
elements = tmp;
matfud -
Hello. I am trying to develop a VI for an FPGA target and I'm trying to make it so whoever is using the VI can specify the size of an input array when they instantiate it (such as by having an input to the VI that says "max array size" or something). So far it seems like the only way to do something like this is to go into the VI itself and manually set the array size for each input array for the VI (i.e. open the VI, right click on each input array, select "Set Dimension SIze", choose "fixed", set number of elements). I'd like to have one point where I can set the size of all the arrays at once (since in my case they are all the same size), and let the person using the VI set it to the proper size for whatever application they are using it for (to be clear, let's say I have two uses for this VI, and in one case I have an input array of size 100 and in anohter use of size 1000, I'd like to be able to set these somehow instead of doing it through the dialog). Thanks.
Solved!
Go to Solution.Unfortunately, per-call configuration of array size is not something that is supported today. This is a great idea, I would suggest that you post it on the FPGA Idea Exchange so we can get a feel for how many other people need this same feature.
-
How do I determine array size in a formula node
I am feeding an array into a formula node to perform an operation on. However the size of the array can be an arbitrary size. How can I determine its size to use for iterating through a for loop?
I suppose that I could add another input that is fed with the array size from the array palate but I would like to know if it can be done inside the formula node itself.Your own advice is the only and best one.
greetings from the Netherlands -
Setting array size, effect on memory
Does setiing the array size to a huge no has any affect on the memory, performance and is it considered good programming. If not what are the other options?
String [] arrayString = new String [2354];Your question is rather ambiguously worded.
In Java arrays cannot be resized, so you should set the array to the exact size you need. If you need a huge array, create one. If you need a small array, create one. If you don't know how large it should be, or need it to be dynamically sized, use any of these great classes - ArrayList, HashMap, HashSet, etc... Try reading the Java API documentation on these classes...
And yes, when you create a huge array, it actually allocates the space for each element in the array right then, and in fact initializes each with the default values of null, zero, or false depending on the type of the array. -
How to adjust a "control array" size
I have a program that creates a digital PWM signal with variable duty cycle. The duty cycle changes every 50 ms, but the overall wave frequency stays at a frequency determined by the user. I have the VI attatched.
My problem is this...I need to be able to control the overall cycle time. This means the size of my array of duty cycles needs to adjust based on the cycle time (i.e. a cycle time of 1 second would require 20 of the 50 ms slots, while a 1.3 second cycle would need 26).
I currently have only 4 slots in my array, meaning the total cycle time is .2 s. I understand how to manually add and remove elements to the array, but I can't figure out how to add a control to it so that the array size changes automatically, allowing much quicker entry of data. As of now I can make it work, it just takes super long to add or delete array elements. The ideal situaton would have a constant control for cycle time divided by 50 that would change the array size.
I can't find any info on this, and I think I even saw a post asking that this kind of feature be added. I'm relatively new to this program.
Thanks
Solved!
Go to Solution.
Attachments:
var_duty_cycle.vi 25 KBCurrently, your VI is a one-shot deal. What you need is a state machine that updates the pct duty cycle array control as a function of the frequency while the current I/O code is idle.
I would use an array of clusters, where each cluster contains e.g. a sequence number, a duty cycle, and a string as element label. Show the scrollbar and set the size whenever the relevant inputs change. Do you want to reset the current setting when the number changes or do you want to retain the current settings as much as possible? You could just use the existing values, reshape to the larger or smaller size, and write it back to the control via a local variable. Set all elements except the percent to disabled so they act as indicators and cannot be changed by the user.
(You also need to program around it if the operator tries to manually add more elements. A better solution would be this idea, so vote for it .)
Some more general comments bout your code:
Why do you use extended precision floating point. All your waits are internally just integers. EXT makes no sense
There is a primitive for 1/x. However, you could just do a 1000/x and eliminate the multiplication afterwards. SInce you are dealing with integers, you can even do the division using quotient&remainder. Depending on the allowed frequency range there are possibly no orange data needed at all.
Make the diagram constant representation match the rest of the code.
The pulses/50ms indicator belongs before the loop. No need to recalculate and refresh it over and over from the same input values.
LabVIEW Champion . Do more with less code and in less time . -
How to increase Array size while copying from remote table
Hi everyone,
I am using remote copy to copy 900,000(9 millions) records to local data base ,but it is taking long time obviuosly. The message i see while copying is
Array fetch/bind size is 15 (array size is 15)
can Array size be changed to make copy faster or
any otherway to copy 9 million reocrds fastly?
regards,
KarnaI guess that you are using the 'copy' command in sql*plus.
1. You could export the remote table and import the data into your local table. That perhaps would be efficient.
2. You could increase the array size for example,
SQL> show arraysize
arraysize 15
SQL> set arraysize 5000
SQL> show arraysize
arraysize 5000
SQL> What is the value for sql*plus option 'copycommit'?
SQL> show copycommit
copycommit 0
SQL> -
Two instances of quirky behavior: array size of empty array and tab control freeze
LV 7.1
Array size of empty array. Adding empty arrays to an array of higher dimension produces a fantom array of non-zero size.
Tab control freeze. An event structure with checked 'lock front panel until the event case completes' option permanently freezes the front panel in certain special circumstances.
Zadortst wrote:
Tell me if you still think this makes sense.
Whew, let me look at this tonight after I activate the 4D module in my brain.
(I think it makes sense, though ) Generally I look at the product of the dimensions array to determine if an array is empty. You can initialize a multidimensional array with some dimensions at zero and it is reproduced nicely in the array size output. Also the "Empty array" tool correctly identifies it as empty, even if some dimensions are nonzero.
Message Edited by altenbach on 03-15-200612:42 PM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
init.png 3 KB -
Hi All,
I have a small question.I am using SunOS 5.9 and gcc 4.0 compiler.
Please take a look at the below code
When I compile the following program under gcc 4.0 it doesn't give me any compiler error and even the size comes correctly.
#include<stdio.h>
int main()
int c;
scanf("%d",&c);
int x[c];
printf("sizeof =%d\n",sizeof(x));
But when I use visual studio 2003 compiler it gives me error ( like cannot allocate an array of constant size 0).
I am bit confused as normall array size should be static rather during runtime.And I am not using malloc in this case also.
Could you please clarify this.Or is it possible to allocate the array size like this in advanced compilers?
Looking forward for your response.Hello.
I just tested initializing an array with a variable. It works under GCC 3.3.2. I know no other C compiler which is able to do this! In a C tutorial in the internet I found this:
You cannot initialize an array using a variable. [...] For example:
int x = 5;
int ia[x];Obviously initializing arrays with variables is a GCC extension.
If the compiler supports the "alloca" instruction you may use this instead:
int x = 5;
int *ia = (int *)alloca(sizeof(int) * x);
// sizeof(ia) is 4 or 8 (32 or 64 bit) here independent of xMartin -
I think I may have stumbled across (another) PDA bug.
On my desktop the array size corectly returns the number of elements. On my PDA it returns zero - has naybody else witnessed this? My array is a 1D string with 8 elements.
Thanks in advance.I have got to the bottom of this one! It appears that there is an inconsistency in the operation of the Spreadsheet String To Array function.
For some reason I had made the array type terminal a plain string ( not an n-dimension array). On a PC this seems to work OK, when it is compiled for PDA it does not return an array.
By changing the string to a 2D string array it works on both the PC & PDA.
Does not work on PDA:
Works on PDA
ssk
Message Edited by ssk on 03-05-2009 07:53 AM
Attachments:
Works.JPG 16 KB
Does_Not_Work.JPG 15 KB
Maybe you are looking for
-
Apple graphics card vs flashed graphics card
My old Apple Cinema Display went down today, and I had to buy an Apple Cinema LED 24" display with a mini displayport connector. Do the Apple cards show the gray Boot Screen through the mini display port? I'm am told the flashed cards will not show t
-
Saving keyframe size settings when opening Flash CS3
Is there any way within Flash CS3 that allows the default size settings for the keyframes within the timeframe from the standard "Normal" to another size, such as "Medium"? Screenshot of keyframe settings in Flash CS3 I would love it if Flash CS3 all
-
Compilation error..Please Help
I had recently installed the jdk1.3 (Win ME version). I have no problem with my path variable although I doubt the classpath variable setting, which is given as follows. D:\java\p_java>set classpath=%classpath%;D:\java\jdk1.3.1_02\jre\lib;D:\java\jdk
-
My Aperture crash after upgrade to 3.4. Pls help !
My Aperture crash after upgrade to 3.4. Pls help!
-
How do I install password for my voicemail so I don't have to type it in every time
My old Motorola razor you installed the password and you didn't have to put in every time Thanks for any input Mark