I am new to programming and I am trying to fix the Java code errors below and no matter what I do I cannot get it to compile and run. Would anyone mind helping me with this and explain what I am needing to do. Thank you.

import java.util.Scanner;
public class SyntaxError
{
            public static void main(String[] args)
            {
                        System.out.println(Enter two numbers to multiply.)
                        Scanner keyboard = new Scanner(System.in);
                        n1 = keyboard.nextInt();
                        n2 = keyboard.nextInt();
                        int product = n1 * n2;
                        System.out.println("The product is " + product);
            }
}

Recommended Answers

All 6 Replies

You forgot to enclose your string with double quotes. It should be like this:

System.out.println("Enter two number to multiply.");

You also forgot to declare the datatype of your variables before use. So the following lines

int n1 = keyboard.nextInt();
int n2 = keyboard.nextInt();

//Please carefully look on your code I changed that and run neetely check your //mistake....

}import java.util.Scanner;
public class SyntaxError

            public static void main(String[] args)
            {
                        System.out.println("Enter two numbers to multiply.");
                        Scanner keyboard = new Scanner(System.in);
                        int n1 = keyboard.nextInt();
                        int n2 = keyboard.nextInt();
                        int product = n1 * n2;
                        System.out.println("The product is " + product);
            }
}

@haris.nattukal: did you add anything other than what Freshly already mentioned 5 days ago?
If so, please add some explanation of what and why you changed it, so the OP can learn from it, otherwise, I hope you realise the futility of posting this code.

Freshly's corrections worked perfectly! Thank you very much, I greatly appreciate it.

Hello everyone, I have this simple java program that can multiply two numbers (thanks to Freshly helping me fix a few errors) and I am either wanting to expand or add to it without it becoming too complicated. I am new to programming and just wanting to see if I could slowly increase the complexity of this simple Java program overtime and was wondering if anyone has any ideas? I thought about maybe adding a part to where I could add a person’s name, hours worked, and dollars per hour, but I am not sure how to start? Thanks!

import java.util.Scanner;
public class SyntaxError
{
            public static void main(String[] args)
            {
                        System.out.println("Enter two numbers to multiply.");
                        Scanner keyboard = new Scanner(System.in);
                        int n1 = keyboard.nextInt();
                        int n2 = keyboard.nextInt();
                        int product = n1 * n2;
                        System.out.println("The product is " + product);
            }
}

Maybe just keep with the calculator for a bit? (Small steps for an easy journey)
a) Keep doing multiplications until the user signals "stop", eg by entering zero for eiher number (if test, a loop)
b) Offer choice of multiply or divide (Strings, if test)
b) Offer add/subtract/mult/div (use a switch)

Also:
get closer to real life by making it handle mistakes by the user (eg types something that's not a valid number)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.