I have a question about HTML and Javascript

90
March 22, 2021, at 04:30 AM

I'm working on a website for a school project and I'm using html and JavaScript to write it. I wrote a program in java that I'm going to add to the website I'm a little confused about how to implement it into the website, do I just copy paste it into the script of the html or am I missing something

<script type ="text/javascript">

</script>

would I just copy paste the java code in-between there?

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class SearchForWords {
    public static void main(String[] args) {

        String filename = "input3.c";
        try {
            Scanner sc = new Scanner(new File(filename));
            int lineCount = 1;
            while(sc.hasNextLine()) {
                String line = sc.nextLine();
                if(line.contains("gets")) {
                    System.out.println("Use fgets() instead of gets() : Found in line " + lineCount);
       
                lineCount++;
            }
            sc.close();
        } catch (FileNotFoundException e) {
            System.out.println("File not found");
        }
    }
}
Answer 1

No, copy pasting the code will not work. The reason was already given: java very much is not javascript, they are different languages and have nothing to do with each other.

If we are talking about how to put javascript code into HTML you have two options: copy paste it in or import it using the src of a script tag: Where should I put <script> tags in HTML markup?

READ ALSO
How to exit infinite loop using &ldquo;Enter&rdquo; key?

How to exit infinite loop using “Enter” key?

So, I'm trying to exit the infinite loop using the "Enter" key, and I'm kind of stuckCan someone please help me to see where I'm going wrong? Would be highly appreciated

191
How can I increase the number of cards per row using react-bootstrap &lt;CardColumns&gt; component?

How can I increase the number of cards per row using react-bootstrap <CardColumns> component?

I am struggling a bit with how to format React-Bootstraps <CardColumns> component

110
ExpressJs &amp; PassportJs returning &#39;missing credentials&#39; on successful login

ExpressJs & PassportJs returning 'missing credentials' on successful login

I have been trying to solve this for hours, I made everything posts say and still not workingThere are another posts in stack overflow about this, but I simply can't find a solution for my code

157
Django using Celery not performing my task

Django using Celery not performing my task

I have been trying for the past 3 days to get django to perfom asynchronous tasks on a periodic scheduleCame across Celery which seemed like a perfect match for my problem but the more I read online the more problems there seemed to exist that I had prepared

130