Click here to Skip to main content
15,744,193 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have the request for the numbers on the JoptionPane and the Command line but I dont know how to store them to multiply them together, can you please have a look and suggest any options I can use to get it working, here is my current code :

import java.util.Scanner;
import javax.swing.JOptionPane;
 * @author Adam
public class Inputting {

    public static void main(String[] args) {
        Scanner Scan = new Scanner (; // Creates the Scanner to allow input

        System.out.print("Enter a Number");
        String input = null;
        String first =;

        String Second; // Second Declared as a string
        Second = JOptionPane.showInputDialog("Enter Another Number");
        double d = Double.parseDouble(Second);

        System.out.print("What is your Name?");
        String name =;

        String Age; // Age Declared as a String
        Age = JOptionPane.showInputDialog("Enter your age ");

        System.out.print( name + " "+ "(Aged" + " " + Age +  ")" + "," + "your answer is " + first*Second );


Sergey Alexandrovich Kryukov 21-May-15 12:46pm    
What's your problem?
Adamdew93 21-May-15 13:09pm    
The program seems to have an issue with the '*' as the error "bad operand types for binary operator " appears and I am struggling to get rid of it

1 solution

Ok really basic:

You got your input values as String.

String first =;
Second = JOptionPane.showInputDialog("Enter Another Number");

After this you convert only
into a numeric value, but don't use it!

double d = Double.parseDouble(Second);

Solution is to convert
into numeric values like this:

double firstValue = Double.parseDouble(first);
double secondValue = Double.parseDouble(Second);

// get the result
double result = firstValue * secondValue;

Now you can print it:

System.out.print( name + " "+ "(Aged" + " " + Age +  ")" + "," + "your answer is " + result );
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900