-1

I'm just starting to learn Java, and i ran into a problem while trying to multiply.

import java.util.Scanner;

public class Kertolasku {

    public static void main(String[] args) {
        Scanner lukija = new Scanner(System.in);

        System.out.println("Please give a number");

        int first = Integer.valueOf(lukija.nextLine());

        System.out.println("Please give another number");

        int second = Integer.valueOf(lukija.nextLine());

        int v = first*second;

        System.out.println(first + " * " + *second + " = ");



        // toteuta ohjelma tänne

    }
}

I've been stuck on this for about an hour or two. I have no idea on what to do. May someone help me please. Thanks in advance!

1
  • 2
    typo - remove the * from *second
    – Eran
    Commented Nov 25, 2019 at 9:36

2 Answers 2

1

Remove the * before second in the last line and add + v too so you actually get the result afterwards.

import java.util.Scanner;

public class Kertolasku {

    public static void main(String[] args) {
        Scanner lukija = new Scanner(System.in);

        System.out.println("Please give a number");

        int first = Integer.valueOf(lukija.nextLine());

        System.out.println("Please give another number");

        int second = Integer.valueOf(lukija.nextLine());

        int v = first*second;

        System.out.println(first + " * " + second + " = " + v);

    }
}
2
  • Thank you so much, i didn't even know it can multiply the numbers without the actual "*" in it. It's my 2nd day of learning Java and i basically know nothing yet. Without your answer i would have been stuck here for a while!
    – Lerby
    Commented Nov 25, 2019 at 9:43
  • @Lerby No problemo, glad I could help. If it worked don't forget to click the tick under the score of the answer to mark it as the correct answer.
    – THess
    Commented Nov 25, 2019 at 9:45
0

The problem is here:

System.out.println(first + " * " + *second + " = ");

remove the * from *second:

System.out.println(first + " * " + second + " = ");

Also, if you want to print out the result, add the v in the string:

System.out.println(first + " * " + *second + " = " + v);

Not the answer you're looking for? Browse other questions tagged or ask your own question.