samedi 6 février 2016

Alphabet to numbers?

Why am i getting this error:

AlphaPos.java:15: error: cannot find symbol String letter = kbd.NextLine();

symbol: method NextLine() location: variable kbd of type Scanner 1 error

It's probably something so simple.

Thanks for the help in advance!

import java.util.Scanner;

public class AlphaPos
{
   public static void main(String[] args) 
   {
         Scanner kbd = new Scanner(System.in);

  int position = 0;

  String alphabet = "abcdefghijklmnopqrstuvwxyz";
  String alphabetCAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

  System.out.print("Please enter an upper or lower case letter:");
  String letter = kbd.NextLine();

  char L = letter.charAt(0);

 if(Character.isLowerCase(L))
 {
  for(int i = 0 ; i < alphabet.length()-1; i++)
    {
     if(alphabet.charAt(i) == L)
        position = i+1;
    }   
  System.out.print("You entered "+letter+" in upper case it is number "+ position +" in the alphabet.");      
   } 
   if(Character.isUpperCase(L))
  {
  for(int i = 0 ; i < alphabetCAP.length()-1; i++)
    {
     if(alphabetCAP.charAt(i) == L)
        position = i+1;
    }   
  System.out.print(" You entered "+letter+" in upper case it is number "+ position +" in the alphabet.");      
  }
  else 
     System.out.print(" You entered " +letter+ " and it is no in alphabet.");      


   }
 } 

Aucun commentaire:

Enregistrer un commentaire