d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > New To Java
Add Reply New Topic New Poll
Member
Posts: 2,142
Joined: Mar 31 2007
Gold: 0.00
Feb 16 2022 04:13pm
I am in a first year programming class and was given a problem but have no clue where to begin and am kinda lost on all of this.

Is anyone able to give me some guidance

here is the problem set:


Problem 6: ASCII encodings
People read/write text using alphanumeric characters (i.e. 'a', 'b', 'c') whereas computers are
limited to processing purely numerical data. Therefore, in order for machines to process text,
that text must first be encoded as numbers. ASCII is the most common mapping between
characters and numbers. Your task is to take the raw numerical data used by a computer, and
convert it into an english message that a person may easily read.
Facts:
● the char datatype maps characters as ascii codes
● ascii codes are integer numbers
● Java may easily convert between char codes and integers
Input
Your solution must take in six integer inputs. Each input represents an alphanumeric character.
Output
Your solution must display the six-lettered english message as a single string with no spaces
between the characters
Member
Posts: 1
Joined: Feb 26 2022
Gold: 0.00
Feb 26 2022 11:05am
you can cast types (like int) to another type (like char).
if you wrote out something like :

char b = 98;
System.out.println(b);

the output will be b, not 98. because java goes hey thats a char 98 isnt a char but 98 is the numerical representation of the char 'b' so lets output that.

say your code is like this. the (char) part explicitly casts the int to a char, and if you dont do that casting this wouldnt compile.


int[] arr = {98, 99, 100, 101, 102, 103};

char one = (char)arr[0];
char two = (char)arr[1];
char three = (char)arr[2];
char four = (char)arr[3];
char five = (char)arr[4];
char six = (char)arr[5];

System.out.print(one);
System.out.print(two);
System.out.print(three);
System.out.print(four);
System.out.print(five);
System.out.print(six);

this would output: bcdefg
so basically they want you to take the input, cast the ints to chars, and print them out. look into explicit and implicit casting of primitives/data types if you need more info.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll