爪哇 - 用户输入添加到3阵列? (并行阵列) [英] Java - Add user input to 3 arrays? (Parallel Arrays)

查看:124
本文介绍了爪哇 - 用户输入添加到3阵列? (并行阵列)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有3个平行阵列。我需要,将允许用户添加到这些阵列的方法。以及另一种方法,以便能够识别一定的信息并取出它。以及另一种方法,以确定的项目和编辑/改变该项目的内容,在阵列中

So I have 3 Parallel Arrays. I need a method that will allow for the user to add to these arrays. As well as another method to be able to identify a certain item and remove it. As well as another method to identify an item and edit/change the contents of that item in the array.

这是我的3阵列...

These are my 3 arrays...

我需要添加电脑的品牌名称:
的String [] computerBrand

I need to add the brand name of the computer to: String[] computerBrand

我需要的处理器速度加入到:
双[] computerSpeed​​

I need to add the processor speeds to: double[] computerSpeed

和我需要电脑的价格加入到:
双[] computerPrice

and I need to add the computers price to: double[] computerPrice

的第一阵列(串)持有的计算机的品牌名称。 (戴尔)
第二阵列(双)持有的计算机的处理器速度。 (2.5)
第三阵列(双)持有的计算机的价格。 (1500)

The first array (string) holds the brand name of computer. (Dell) the second array (double) holds the processor speed of the computer. (2.5) the third array (double) holds the price of the computer. (1500)

我如何采取用户输入,并把它们在数组中?

How do I take user input and put them in the array?

(我不能使用的ArrayList)

(I CANNOT USE ARRAYLISTS)

推荐答案

有关服用输入看看扫描仪类。

For taking input look at the Scanner class.

扫描仪

有关添加值的数组只是这样做:

For adding the values to your arrays just do this:

computerBrand [I] =< value_brand取代; 结果
computerSpeed​​ [I] =< value_speed取代; 结果
computerPrice [I] =< value_price取代; 结果
我++;

,其中这3个值是一个通过扫描仪读取,结果
I 一些指数/计数器整型变量。

where these 3 values are the one read by the Scanner,
and i is some index/counter integer variable.

但首先要确保你初始化数组例如:

But first make sure you initialize your arrays e.g.:

computerBrand = new String[100];
computerSpeed = new double[100];
computerPrice = new double[100];

这篇关于爪哇 - 用户输入添加到3阵列? (并行阵列)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆