Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing charAt method, won't add them as an Int, and wont print as string. Will explain better
    primarykey
    data
    text
    <p>Alright, so here is my code: </p> <pre><code>import java.util.Scanner; public class CarRental { public static String model; public static int letternum; public static String plate; public static String letter; public static int total; public static String alphabet = "abcdefghijklmnopqrstuvwxyz"; public static void main(String[] args) { Scanner input = new Scanner(System.in); //System.out.println("Car Model:"); //model = input.nextLine(); System.out.println("License Plate: "); plate = input.nextLine(); char one = plate.charAt(0); char two = plate.charAt(1); char three = plate.charAt(2); total = one + two + three; letternum = total % 24; char letter = alphabet.charAt(letternum); System.out.println("" + letter + total); } } </code></pre> <p>What is going on is this, I'm trying to make it take my license plate input and take the characters at the places for 0, 1, and 2. Which in a license plate would be the three letters. Then, i'm trying to take their ASCII Values, add them all together and set them to the int "total". Then to find a Letter that is supposed to be in front of the total value, I find the remainder of the total by using % 6. Then it will take that value, and whatever number it is, say it is 4, it will take the 4th letter in the string "alphabet" and set that to a the char "letter". Then what it should do is print out the letter followed by the totals of the ASCII Value.</p> <p>Here is an example of what is my input with expected outcome, followed by its ACTUAL outcome.</p> <blockquote> <p>License Plate: CPR 607</p> <p>Output: E836</p> </blockquote> <p>My output with the exact same license plate is: </p> <blockquote> <p>License Plate: CPR 607</p> <p>n229</p> </blockquote> <p>I'm not sure what I'm doing wrong, but my best clue is that the fact that it is a char, it is treating it like its ASCII Value, rather than its String value(which i'm actually trying to get)</p> <p>If anyone could suggest some tips, it would be a great help. Not necessarily code I can just leech off of, but how I should go about doing this the right way!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload