-1

I`m trying to write java program that take license number from one file and put it in another file. This what I wrote until now:

import java.io.File;

import java.util.Formatter;

import java.util.Scanner;

public class license {

    public static void main(String[] args) {
        openFile();
        readFileAndConvert();
    }

    private static Scanner x;

    // Open original license file

    public static void openFile() {

        try {
            x = new Scanner(new File("C:\\Users\\me\\Desktop\\originalLicense.txt"));
        } catch (Exception e) {
            System.out.println("Error");
        }
    }

    public static void readFileAndConvert() {

        String licenseNum;
        Formatter newLicense = null;

        while (x.hasNext()) {
            licenseNum = x.next();

            if (licenseNum == "123") {  

                try {
                    newLicense = new Formatter("C:\\Users\\me\\Desktop\\newLicense.txt");
                } catch (Exception e) {
                    System.out.println("Error");
                }
                newLicense.format("%", licenseNum);
            }
        }
    }
}

I used youtube videos to write this and now I can`t find the problem, Is anybody can guess what can be the problem?

1 Answers1

0
newLicense.format("%", licenseNum);

This is not a valid format string. Did you mean "%s"?

NB Don't use == to compare String values. Use .equals().

Did you consider consulting the documentation? Don't waste your time trying to learn computer programming from YouTube.

user207421
  • 305,947
  • 44
  • 307
  • 483