Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


jas
ARRAY SIZE.
3 Answer(s)      6 years and 2 months ago
Posted in : Java Beginners



Advertisement
View Answers

September 30, 2008 at 10:23 AM


Hi friend,


Do some changes for compile and run the code correctly

int num2= numbers*2;
B.add(num2);


Code :

import java.io.*;
import java.util.ArrayList;


public class CopynDouble1
{
public static void main(String[] param){
try{
BufferedReader n = new BufferedReader(new InputStreamReader(System.in));

ArrayList<Integer> A = new ArrayList<Integer>(); //array A
ArrayList<Integer> B = new ArrayList<Integer>(); //array B

System.out.print("Input number: ");
String userInput = n.readLine(); //read Input;
int numbers = Integer.parseInt(userInput); //integer version of userInput;

while(numbers != 0){
A.add(numbers);
int num2= numbers*2;
B.add(num2);
System.out.println(B); // Don't know how to print array B in this case.
System.out.print("Input number: ");
userInput = n.readLine();
numbers = Integer.parseInt(userInput);
}
}


catch(Exception e){
}
}
}

For read more information :
http://www.roseindia.net/java/

Thanks



September 30, 2008 at 12:01 PM


Hi

B is ur ArraayList Object, So u can.t use any aritmatic operation on that object.

in ur code just modify
while(number !=0){

A.add(number)
B.add(number*2);

}

Thanks
Rajanikant


October 2, 2008 at 2:24 AM


ThankYou Very Much Rajanikant and Deepak.
I can't ThankYou Guys enough for helping me in solving this code.



Related Tutorials/Questions & Answers:
calculate size of array
calculate size of array  Is it possible to calculate the size of array using pointers in Java
ARRAY SIZE!!! - Java Beginners
ARRAY SIZE!!!  Hi, My Question is to: "Read integers from... to initialize the array when you don't know the size of the array. Just to get...). Vector is a growable array. Here no need to define the intial size of ur
Advertisements
ARRAY SIZE. - Java Beginners
ARRAY SIZE.  Thanks, well that i know that we can use ArrayList... the elements in array A. Then doubled array A by multiplying it by 2 and then storing it in array B. But gives me error. import java.io.*; import
JavaScript array size
JavaScript array size     ... you in understanding JavaScript array Size. The code shows you a HTML Page ... is assigned to array [count]. The function show( ) include the variable string return
Create array of random size
Create array of random size In this tutorial, you will learn how to create... the Random class, we have set the random size to array. We have stored... the size of array, the code catch out-of-bounds exceptions and display "
Get Array Size
Get Array Size       To calculate length of the given array we have used length property. It returns the length of the given array.          
JSP List Size
of the list. The JSP List Size uses array list object to add the elements and finally... of elements in the array. l.size : The method returns the size list... JSP List Size     
Array
Array  can we create an array of size 1 lakh in java programming
Size of commarea
Size of commarea  hii, What is the size of commarea?   hello, Default size of commarea is 65k
Array
("Enter Range: "); int size=input.nextInt(); int array[]=new int[size]; System.out.println("Enter Array Elements: "); for(int i=0;i<...Array  How do i insert elements into an array up to a limit from
Size in FLex
Size in FLex  Hi..... What is the difference between width, explicitWidth, measuredMinWidth, measuredWidth, and percentWidth? please tell me about that difference Thanks
Size in FLex
Size in FLex  Hi... I just want to know about... What happens in measure()? measuredHeight, measuredWidth, measuredMinHeight, measuredMinWidth are set. please give me an example with description... Thanks
JavaScript Array undefined
JavaScript Array undefined       Undefined array is a condition that occurred when a user want to print an array element more than the declared size of element that an array
C Array default values
in Array. The example below contains an array arr of integer type. The maximum size of the array is 4. We have allocated only two values in the array like this:  ... C Array default values     
Array in Java
An Array is the static memory allocation that holds a fixed number of values of same type in memory. The size or length of an array is fixed when the array...[] = {50,60,70,80,90}; The size of this array will be 5 elements. *There is another way
in_array
in_array  in_array in php
is _array()
is _array()  is_array() in php   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
is _array()
is _array()  is _array()   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
Array
Array  how can i use elements of an array in a circular form? that is if the searching of the element reach the last elements of the array, then it will start serching from the begining of the array
Array
Array  is it possible to define array like this..? int[] intArray = new int[] {4,5,6,7,8}; Explain...?   Yes, you can. Java Initialize Array
Array
Array  What if i will not declare the limit index of an array, how will I declare an array and store values with it using loop?   Hi Friend...(System.in); int array[]=new int[5]; System.out.println("Enter Array Elements
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  WAP in java to store 6 element in array P and 4 element in array Q. Produce the third arra y R containing all element from p & q
array
array  array memory allocation is dynamic or static in java   Java Arrays have dynamic memory allocation
array
accepts a pointer to integer which represents an array of integer.After that this method prints the entire of the array numbers to the monitor. include using std::cout; using std::endl; void printArray(int *array, int count
array
array  take a 2d array and display all its elements in a matrix fome using only one for loop and ple explain the program in below
array
array  create an array in which no element is duplicate. if duplicate then tell to user duplicate. duplicacy is tell to user during when he enter the element
array
array  create an array in which no element is duplicate. if duplicate then tell to user duplicate. duplicacy is tell to user during when he enter the element
array
array  How to store the results of mysql query in an array... qurey in array: "select distinct(EMPLID)from tblwork where EMPLID not in (select... store the result in array
Advertisements
 

 

 

DMCA.com