无法获取数组以在下一个数组槽中存储输入(Cannot get array to store input in next array slot)
我正在创建一个银行系统,似乎无法将客户名称的名称存储在一个数组中。 最后一个客户名称仅在下一个客户上被覆盖。 这些是关于数组的线。
ArrayList<String> allnames1 = new ArrayList<String>(); System.out.println("Please enter account holders name:"); allnames1.add(sc.nextLine()); System.out.println("Account Created. Overview and Balance: " + "\n" + allnames1);
发生这种情况后,用户将被带回另一个班级的“主菜单”。
I'm creating a banking system and can't seem to store the name of the customer names in an array. The last customer name is just overridden on the next customer. These are the lines concerning the array.
ArrayList<String> allnames1 = new ArrayList<String>(); System.out.println("Please enter account holders name:"); allnames1.add(sc.nextLine()); System.out.println("Account Created. Overview and Balance: " + "\n" + allnames1);
After this happens the user is taken back to the "Main Menu" in another class.
原文:https://stackoverflow.com/questions/35240277
更新时间:2022-06-20 13:06
最满意答案
您正在重置
while
循环的每次迭代中的因数组,而不是每个数字。将其改为如下所示:
for ($x = 3; $x <= 100; $x++) { $y = 2; $factors = array(); do { if ( $x % $y == 0 and $x != $y) { $factors[] = $y; } $y++; }while ($y <= 10); if (count($factors) == 0) { echo "$x is a prime number.<br />"; }else { echo " The factors of $x are: "; foreach($factors as $factor) {echo "$factor ";} echo "<br />"; } }
You're resetting the factors array on each iteration of the
while
loop, rather than for each number.Change it to something like:
for ($x = 3; $x <= 100; $x++) { $y = 2; $factors = array(); do { if ( $x % $y == 0 and $x != $y) { $factors[] = $y; } $y++; }while ($y <= 10); if (count($factors) == 0) { echo "$x is a prime number.<br />"; }else { echo " The factors of $x are: "; foreach($factors as $factor) {echo "$factor ";} echo "<br />"; } }
相关问答
更多-
citizen手表价格最少多少钱[2023-10-20]
100 -
public static void main(String[] args) { int array[]= new int[100]; { int index=0; for(int i=0;i<100;i++) { int m; m=search(i); if(m==1||m==2 || m==3 || m==5){ array[index++]=i; } } }} 看看。我希望它会有所帮助。 public static void main(String[] args) { int array[ ...
-
这个程序,有点适合FreshLib工作就像一个魅力。 该程序的核心是相同的,我只是添加了一些控制台输出。 (而且,它是FASM语法)所以,你只是没想到程序运行正常。 include "%lib%/freshlib.inc" @BinaryType console include "%lib%/freshlib.asm" start: InitializeAll XOR eax, eax ;; Set eax to 0 MOV ecx, 100 ;; ...
-
找到介于2和100之间的因子600851475143(Finding a factor of 600851475143 that lies between 2 and 100)[2023-07-11]
PHP手册:算术运算符 : 除法运算符(“/”)返回一个浮点值,除非两个操作数是整数(或者转换为整数的字符串),并且这些数字可以被整除,在这种情况下将返回一个整数值。 您的本地计算机正在使用32位整数,其中最大的是2147483647.您可以使用32位版本,也可以使用7之前的PHP版本。 因为600851475143大于你的最大整数,所以它被转换为浮点数,因此你的除法也将总是返回一个浮点数。 如果你 var_dump(600851475143/71) 在你的本地系统上你会得到 float(84626968 ... -
按因素写的(write.table by factors)[2022-07-14]
plyr包和d_ply使这很容易。 定义一个写入文件的函数: myfun <- function(x) { filename <- paste0(unique(x$years), '.txt') write.table(x$random_numbers, filename, row.names=F, col.names=T) } 然后用d_ply调用它: d_ply(testDF, .(years), myfun) 但要小心这一点......因为它会默默地将一堆文件写入您当前的工作目录! the ... -
简化目标:您需要枚举所有整数组合,这些组合相乘以形成特定产品,其中整数的数量是固定的。 要解决这个问题,您只需要对目标数进行素数分解,然后使用组合方法从这些因子中形成所有可能的子产品。 (一旦你拥有所有可能的子产品,也很容易包含一些其他的谜题约束,比如没有条目可以比max_entry ,并且你有一个固定数量的整数可以使用, n_boxes_in_domain 。) 例如,如果max_entry=6 ,则n_boxes_in_domain=3 , target_number=20 n_boxes_in_dom ...
-
应该很容易。 您可以使用array_sum和array_map 自定义函数 : $sum = array_sum($all_values); $result = array_map(function ($value) use ($sum) { return $value * 100 / $sum; }, $all_values); 您可以在返回之前投射结果,但我不知道您想要什么类型。 短期演示 。 Should be easy enough. You can use array_sum and arr ...
-
您正在重置while循环的每次迭代中的因数组,而不是每个数字。 将其改为如下所示: for ($x = 3; $x <= 100; $x++) { $y = 2; $factors = array(); do { if ( $x % $y == 0 and $x != $y) { $factors[] = $y; } $y++; }while ($y <= 10); if ...
-
您需要在每次迭代结束时将div_count设置为零: def n_factors(x, lower, upper): int_counter = 0 # integer counter div_count = 0 # divisor counter for i in range(lower, upper+1): for j in range(1, i + 1): if (i%j)==0: div_count += ...
-
试试这个 int n=3; for(int i=100; i>=40; i--) { if(i%n == 0 ) printf("%d", i); } Try this int n=3; for(int i=100; i>=40; i--) { if(i%n == 0 ) printf("%d", i); }