herat_000 0 Newbie Poster

hi...
i m beginner...and i m having trouble with following code:and the problem is that when i try to input name then it is taking blank...like... i m first asked value of n if i enter 2 then it automaticaly goes to acc type .....not taking name...

import java.util.Scanner;
class bank
{
    String name;
    int accNo;
    String type;
    int bal;
    void getdata(String n,int a,String t,int b)
    {
        name=n;
        accNo=a;
        type=t;
        bal=b;
    }
    void deposit(int x)
    {
        bal=bal+x;
    }
    void with(int y)
    {
        if(bal>y)
        {
            bal=bal-y;
        }
        else
        {
            bal=bal;
            System.out.println("Sorry u r withdrawal amt is higher then u balance");
        }
    }
    void display()
    {
        System.out.println("Your name: "+name+'\n'+"And U R balance is: "+bal);
    }
}
class banktest
{
    public static void main(String args[])
    {
        Scanner input=new Scanner(System.in);
        int n;
        System.out.println("Enter no of objects: ");
        n=input.nextInt();

        String s,q;
        int x,y,i;

        System.out.println("Enter the details of Different Holders: ");

            bank o[]=new bank[n];
            for(i=0;i<n;i++)
            {
            o[i]=new bank();

            System.out.println("enter name: ");
            s=input.nextLine();
            System.out.println("enter acc type: ");
            q=input.nextLine();         
            System.out.println("enter acc no: ");
            x=input.nextInt();
            System.out.println("enter balance amount: ");
            y=input.nextInt();
            o[i].getdata(s,x,q,y);
            o[i].display();
            }


    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.