Wrox Programmer Forums
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 11th, 2006, 08:32 AM
Registered User
 
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mafia boy
Default size of the array

hi everyone...i'm new to this forum...and i hope i can get benifit of it
well...my question is : how can i ask the user to enter the number of array? i mean the size of the array is created my the end user and based on that other operation comes.

  â„¢Â®#9829;#2960;#2951;(Mafia BoY)#2951;#2960;#9829;®™
 
Old April 12th, 2006, 03:39 AM
Registered User
 
Join Date: Apr 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey, I'm new here too!
In the other languages, size of the array must be defined at first. Otherwise the program can not be compiled. I began learning Java two days ago. Books don't say Java could compile program without define size of array. So, maybe it is the anwser.

 
Old April 12th, 2006, 04:30 AM
Authorized User
 
Join Date: Mar 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Something like
String[] dArray;
dArray[]=new String[x];
will compile though, where x is an int that's given a value somewhere else in the program.

But I'm confused about what's really being asked here. Are you really asking about arrays, or are you asking a very general question about input from users during programs?

 
Old April 12th, 2006, 07:29 AM
Registered User
 
Join Date: Apr 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mafia boy
Default

hey all....thanx for replying
well...let me explain more, lets say this is my programs output :
- What is The Size of your Array ?
- (example) 4
- (is should display 4 rendom numbers using (Math.random())

thats all ! :)
can anyone explain for me as soon as possible

  â„¢Â®#9829;#2960;#2951;(Mafia BoY)#2951;#2960;#9829;®™
 
Old April 13th, 2006, 08:48 AM
Registered User
 
Join Date: Apr 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't understand your question clearly, I will write the program like this:

//Õâ¸öÀàÑÝʾÈçºÎÊäÈëÒ»¸öÊµÊ ý
import java.io.*;
public class readDoubleNumber
{
    static public double readData()
    {
        char c=' ';
        StringBuffer str=new StringBuffer();
        while(c!='\r')
        {
            try
            {
                c=(char)System.in.read();
                str.append(c);
            }
            catch(IOException e)
            {

            }
        }
        return Double.parseDouble(str.toString());

    }

    public static void main(String[] args)
    {
        double d;
        System.out.println("What is The Size of your Array?");
        d=readDoubleNumber.readData();
        for(int i=0;i<(int)d;i++)
        {
            System.out.println(Math.random());
        }
    }
}
Is it fit your requirement? I'm a Java beginner, we could discuss it!

A fish want to jump higher!
 
Old April 16th, 2006, 08:25 AM
Registered User
 
Join Date: Apr 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

nobody...

A fish want to jump higher!
 
Old April 24th, 2006, 07:41 PM
Registered User
 
Join Date: Apr 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

mafia boyz.YOu havent went to pakages right now.. you talking about geting input from user at run time...When you go forward with ur book u have to read IO..input outputs and other things..so dont b too fast to jump along...leave this concern here read acording to sequance...There are many ways of doing that...Math.random generate random values i know u dont concern them here u want user given array size and user given values..to b placed in an array...just read forward you gona get it later







Similar Threads
Thread Thread Starter Forum Replies Last Post
Label Array With Dynamic Size nevincm C# 1 April 13th, 2007 11:24 AM
creating an array of size 2^16 bits scoobie C++ Programming 2 November 9th, 2005 08:59 PM
Passing php array values to javascript array gkrishna Pro PHP 0 November 6th, 2004 03:20 AM
A subscript must be between 1 and size of array raj03 Crystal Reports 1 July 8th, 2004 02:12 PM
increase the size of the array Beulah ASP.NET 1.0 and 1.1 Basics 1 September 12th, 2003 08:54 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.