如何输入数组长度?

时间:2017-01-26 03:40:32

标签: java arrays

我试图使用.length输入数组的长度,但是错了。 什么是错误的?

return <foo {...{yourData}}></foo>

输出是:

f= open("Passes.py", "r+")
m=open("money.py","r+")
passes= {}
init={}
initial=0
import time
print "Welcome to the virtual banking system"
time.sleep(0.5)
user=raw_input("Would you like to create a new account? 'Y/N'").lower()
if user== "y":
  new_user= raw_input("Create a username:")
  new_pass= raw_input("Create a password:")
  p= passes[new_user]= new_user + ":" + new_pass
  f.write(str(p+"\n"))
  ask=raw_input("Would you like to sign into your account? 'Y/N'").lower()
  if ask=="y":
    user_in=raw_input("Enter your username:")
    if user_in==new_user:
      pass_in=raw_input("Enter your password:")
      if pass_in==new_pass:
        print "Welcome to your account" + " " + new_user
        useropt=raw_input("Would you like to view your balance- enter 1, deposit money- enter 2, withdraw money- enter 3 or exit- enter 4:")
        if useropt=="1":
          print "Your balance is:", initial
        if useropt=="2":
          amountdep= int(raw_input("How much money would you like to deposit?:"))
          initial+=amountdep
          print "Thanks. Your new balance is:", initial
        if useropt=="3":
          amountwith=int(raw_input("How much would you like to withdraw?:"))
          initial-=amountwith
          print "Your balance is:", initial
        i=init[new_user]=str(initial)
        m.write(str(i)+"\n")
      else:
        print "Password not valid"

    else:
      print "Username does not exist"

  else:
    print "Thanks for using the virtual bank."

else:
  user2=raw_input("Do you have an existing account? 'Y/N'").lower()
  if user2=="y":
    existing_user=raw_input("Enter your username:")
    exisitng_pass=raw_input("Enter your password:")
    for passwords in f:
      if passwords==existing_user+":"+exisitng_pass:
        print "Welcome to your account" + " " + existing_user
        useropt2=raw_input("Would you like to view your balance- enter 1, deposit money- enter 2, withdraw money- enter 3 or exit- enter 4:")
        if useropt2=="1":
          for info in m:
            print "Your balance is:", info
        if useropt2=="2":
          amountdep= int(raw_input("How much money would you like to deposit?:"))
          for info in m:
            a=int(info)+int(amountdep)
            print "Thanks. Your balance is:", int(a)
          m.close()
          m= open("money.py", "w")
          m.write(str(a))
        if useropt2=="3":
          amountwith=int(raw_input("How much would you like to withdraw?:"))
          for info in m:
            t=int(info)-int(amountwith)
            print "Thanks. Your balance is:", t
          m.close()
          m=open("money.py","w")
          m.write(str(t))

2 个答案:

答案 0 :(得分:0)

Foreach用于读取集合中的值。

改为使用它。

for(int k = 0;k<numbers.length;k++)
{
    numbers[k] = input.nextInt();
}

答案 1 :(得分:0)

您没有递增索引,因此将您输入的所有值存储在第0个索引中。请尝试:

     for (int i = 0; i < number.length; i++) {
        number[i] = input.nextInt();
    }

    System.out.println("Array:");

    for (int j : number) {
        System.out.println(j);
    }

输出:

What is the value of array?
3
Write the numbers:
1
2
3
Array:
1
2
3