Falcon Northwest
Introduction =====
This past week and
Rudisill Covered B
Q: What does “sic
The content publis
Laparoscopic hepat
Olive Township, Bu
Effort to improve
Rising costs force

[A case of maligna
All relevant data
A new approach to
A. Field of the In
Q: Why a pointer
Fantasy Sports Wh
Cellular distribut
Q: Is there any m
New York Mets: Top
We have developed
Q: How do I make a program that will take user input and convert it to hexadecimal using an array? So far I am stuck on the conversion part of the code. When I use this in my main method, It works as expected and reads the input and outputs the hexadecimal equivalent. for(int i = 0; i < array.length; i++){ System.out.print(array[i] + " "); if(i == (array.length)-1) System.out.println(array[i] + " " + Hex(array[i])); if(i != (array.length)-1){ System.out.print(" "); } } System.out.println(); However, If I want to use this method as a seperate method of its own, it does not work. How do I make it so that this method works in its own method. For example public static String Hex(String input){ for(int i = 0; i < input.length(); i++){ System.out.print(input[i] + " "); if(i == (input.length())-1) System.out.println(input[i] + " " + Hex(input[i])); if(i != (input.length())-1){ System.out.print(" "); } } System.out.println(); return input; } And then I call it like so Hex("Test"); Is this the right way to make a method that will work outside of the method where I used it in. A: You have too many System.out.println() in your code. In the main method, you don't need to use System.out.println(). One of the System.out.print() statements in your main method is not needed either. For example public static String Hex(String input){ for(int i = 0; i < input.length(); i++){ System.out.print(input[i] + " "); if(i == (input.length())-1) System.out.println(input[i]); if(i != (input.length())-1){ System.out.print(" "); } } System.out.println(); return input; } The program might look like this: for(int i = 0; i < array.length; i++) System.out.print(array[i] + " "); if(i == (array.length)-1) System.out.println(array[i]); if(i != (array.length)-1) System.out.print(" "); System.out.println(); for(int i = 0; i < array.length; i++) { System.out.print(array[i] + " "); if(i == (array.length())-1) { System.out.println(array[i] + " " + Hex(array[i])); } if(i != (array.length())-1){ System.out.print(" "); } } System.out.println(); Note that I changed the names of the methods for better readability, as you used the same name in your main method. And how do I use the above code in my main method and call it? Like this: String name = Hex("Test"); A: For starters, in Hex method, you should use input.length() rather than input.length. Instead of: if(i == (input.length) - 1) Use: if(i == input.length() - 1) You also have a useless System.out.print() statement in your main method. In addition, you're making new System.out.println() in Hex method, which is probably not what you want. If I were you, I would use these improvements like so: for(int i = 0; i < input.length; i++){ System.out.print(input[i] + " "); if(i == input.length() - 1) System.out.println(input[i] + " " + Hex(input[i])); if(i != input.length() - 1){ System.out.print(" "); } } System.out.println(); return input; } A: The problem is that you do System.out.print(" " + Hex(array[i])); instead of System.out.println(" " + Hex(array[i])). So for this program your main method should look like this: for(int i = 0; i < array.length; i++) { System.out.print(array[i] + " "); if(i == (array.length) - 1) { System.out.println(array[i]); } if(i != (array.length) - 1) { System.out.print(" "); } } System.out.println(); But for an actual conversion from String to Hexadecimal you can do something like: public static void main(String[] args) { String input = "123aBCD"; String hex = "";