0
Please help me. Question is fill the method number2word() in that program to convert number to char. Thanks
import java.util.Scanner; class PotonganProgram { public static void main (String[] args) { Scanner scanner = new Scanner (System.in); while (scanner. hasNext ()) { int x scanner.nextInt() String word = number2Word(x); System.out.println(word); } } public static String number2word (int number) { //fill the space return str; } }
1 Antwort
+ 1
To convert int to char:
https://www.javatpoint.com/java-int-to-char
But I would not use char because you can only store one character:
char c = '1' --> possible
char c = '12' --> not possible
Use String:
public static String number2word(int number){
return "" + number;
//or return Integer.toString(number);
}