Using charAt method, won't add them as an Int, and wont print as string. Will explain better

后端 未结 4 1249
旧时难觅i
旧时难觅i 2021-01-27 17:58

Alright, so here is my code:

import java.util.Scanner;

public class CarRental {

    public static String model;
    public static int letternum;
    public st         


        
4条回答
  •  北海茫月
    2021-01-27 18:06

    Change these lines:

    int one = (int) plate.charAt(0);
    int two = (int) plate.charAt(1);
    int three = (int) plate.charAt(2);
    

    This will give you the actual ASCII values for the characters.

    If you want something else, you'll have to subtract a constant from each of the values, as jonhopkins illustrated in his comment.

    Subtract 64 to get A = 1, B = 2, etc.

    I see your problem.

    The algorithm is to take the ASCII values of the first 3 characters and add them to the number (the last 3 characters).

    Also, you have to divide by 6 to get the letters A - E. You're dividing by 24.

提交回复
热议问题