public static void main(String args[]) throws IOException { Scanner scanner = ne
ID: 3589205 • Letter: P
Question
public static void main(String args[]) throws IOException {
Scanner scanner = new Scanner(new File("D:/RAMerrors.txt"));
String result;
Double decimal;
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
Scanner input = new Scanner(line);
String hex = input.next();
result = hexToBinary(hex);
System.out.println("Binary of " + hex + ":" + result);
decimal = binaryToDecimal(result);
System.out.println("Decimal value: " + decimal);
}
}
I want to change the system.out.prinln into a system.out.printf, can't figure it out.
Explanation / Answer
Hi
I have modified the code and highlghted the code changes below
Scanner scanner = new Scanner(new File("D:/RAMerrors.txt"));
String result;
Double decimal;
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
Scanner input = new Scanner(line);
String hex = input.next();
result = hexToBinary(hex);
System.out.printf("Binary of %s: %s " ,hex , result);
decimal = binaryToDecimal(result);
System.out.printf("Decimal value: %lf " ,decimal);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.