Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Print statement should be returning “A0” “B1” “C2” “B3”, “C4”, instead returning 6567697173 without wasting too much if your time.
The question is published on by Tutorial Guruji team.
The question is published on by Tutorial Guruji team.
I have a print statement in a loop that should be iterating like this: “A0” “B1” “C2” “B3”, “C4”. It is instead returning 6567697173.
Here’s the code:
MAIN METHOD
public class AdvDotComLauncher { public static void main(String[] args) { AdvDotComTable table = new AdvDotComTable(); table.createTable(5,5); } }
TABLE CLASS
import java.util.ArrayList; public class AdvDotComTable { public boolean createTable(int rows, int columns) { if (rows == 26) { //When true is returned, the program will let the user know they have to choose a lower number return true; } String[] dotComs = {"Pets.com", "Amazon.com", "Target.com", "Apple.com", "Microsoft.com", "Steampowered.com"}; ArrayList<Character> row = new ArrayList<Character>(); ArrayList<Integer> column = new ArrayList<Integer>(); char[] letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray(); int number = 0; while (rows != 0 && columns != 0) { row.add(letters[number]); column.add(number); System.out.print(row.get(number) + column.get(number)); number++; rows--; columns--; } return false; } }
I have no idea what is causing this problem, and any assistance would be appreciated. I am an amateur developer just trying to learn, so it’s probably a silly mistake (sorry about that).
Thanks in advance,
Lyfe
Answer
As said in the comments,
change
System.out.print(row.get(number) + column.get(number));
to:
System.out.print("" + row.get(number) + column.get(number));
You need to do this so you are printing a String
and not a hashCode
(which is an int
eger).
We are here to answer your question about Print statement should be returning “A0” “B1” “C2” “B3”, “C4”, instead returning 6567697173 - If you find the proper solution, please don't forgot to share this with your team members.