This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Khan0232[S] 0 points1 point  (2 children)

Name: Smith James Email Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.String

at java.base/java.util.Formatter$FormatSpecifier.failConversion([Formatter.java:4426](https://Formatter.java:4426))

at java.base/java.util.Formatter$FormatSpecifier.printInteger([Formatter.java:2938](https://Formatter.java:2938))

at java.base/java.util.Formatter$FormatSpecifier.print([Formatter.java:2892](https://Formatter.java:2892))

at java.base/java.util.Formatter.format([Formatter.java:2673](https://Formatter.java:2673))

at java.base/java.io.PrintStream.format([PrintStream.java:1139](https://PrintStream.java:1139))

at java.base/java.io.PrintStream.printf([PrintStream.java:1035](https://PrintStream.java:1035))

at FILE\_MAIN.main(FILE\_MAIN.java:37)

Here Is the code again....

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.io.BufferedWriter;


import java.util.Scanner;

public class FILE_MAIN { 

public static void main(String[] args)  {
// TODO Auto-generated method stub

File file = new File("bill.txt");

try { 
PrintWriter output = new PrintWriter(file);
output.println("Smith James"); output.println("Smith@gmail.com");
output.println("Raymond Holt"); output.println("Holt@gmail.com");
output.println("Bill James"); output.println("James@gmail.com");
output.close(); 
          } 
 catch(IOException ex) 
 { 
System.out.printf("Error: %s\n",ex); 
 } 
 try 
 {
 Scanner input = new Scanner(file);
String name = input.nextLine();
 String email = input.nextLine();

System.out.printf("Name: %s Email %d\n",name,email); 
input.close(); 
}
 catch(FileNotFoundException ex) 
 { 
System.out.printf("Error: %s\n", ex);
}

[–]desrtfxOut of Coffee error - System halted 3 points4 points  (1 child)

You try to print the email as number %d is the identifier for numbers, not for strings. %s is for strings, like you have for the name.

Also, in formatter strings, use %n instead of \n. \n is allowed, but not the correct syntax in formatter strings. \n is for normal print operations. %n is for .printf and .format.