Reputation: 1
I actually just started Java...
I am getting an error as :
Bank.java:24: error: cannot find symbol
sc.nextInt();
^
symbol: variable sc
location: class Bank
1 error
and my code is :
import java.util.*;
public class Bank
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Welcome To The Bank Portal");
System.out.println("1-----Deposit Money\n2-----Withdrawal\n3-----Show Balance\n4----Transfer Money\n5-----Exit");
System.out.println("Enter Your Choice: ");
int a=sc.nextInt();
switch(a)
{
case 1: Bank ac;
}
}
public static void ac()
{
System.out.println("1-----A/C 123321\n2-----A/C 987789");
System.out.println("Enter Your Choice: ");
sc.nextInt();
}
}
Upvotes: 0
Views: 268
Reputation: 27119
sc
is not in scope in the ac
method. It's declared in the main
method, so it's only in scope in the main
method.
To make it available in the ac
method, pass it as a parameter:
public static void ac(Scanner sc)
And to call it (e.g. in main
)
Scanner sc = new Scanner(System.in); // this you already have
...
ac(sc);
As a side note, I'm not sure what you're trying to do, but the ac
method is never called, and Bank ac
in that switch
statement does nothing.
Upvotes: 3