I've been trying the following code to get a char with Scanner:
import java.util.Scanner;
public class PhoneBill
{
public static void main(String[] args)
{
// Create Scanner
Scanner input = new Scanner (System.in);
//Declare variables
char r, p;
double minutes, nightm, daym, totalcost, account;
//Obtain account number
account = input.nextDouble();
//Determine service
System.out.println("Enter r for regular service or p for premium service: ");
char service = input.next(".").charAt(0);
//Logic for regular service
if (service == r)
{
System.out.println("Enter number of minutes talked: ");
minutes = input.nextDouble();
if (minutes >= 50)
totalcost = (10.00 + (minutes * 0.20));
}
//Display account
System.out.println ("The account number is: " + account);
//Display service type
}
}
but I received this error:
PhoneBill.java:29: error: variable r might not have been initialized
if (service == r)
^
1 error
Where is the issue and how to do it in a proper way?