My program is not running | SoloLearn: Learn to code for FREE!

+2

My program is not running

public class Add { double a,b,c; System.out.println("Enter the first number"); a=Double.parseDouble(args[0]); System.out.println("Enter the second number"); b=Double.parseDouble(args[1]); c=a+b; System.out.println("The addition of two numbers is : "+c); }

e

9/16/2020 5:30:33 PM

Shaikh Abdul

17 Answers

New Answer

+3

Shaikh Abdul Because you didn't passed parameter. This is your complete program. import java.util.Scanner; public class Add { public static void main(String[] args) { double a,b,c; Scanner sc = new Scanner(System.in); System.out.print("Enter the first number : "); a = sc.nextDouble(); System.out.println(a); System.out.print("Enter the second number : "); b = sc.nextDouble(); System.out.println(b); c = a + b; System.out.println("The addition of two numbers is : "+c); } }

+3

Shaikh Abdul Where is main method? https://www.sololearn.com/learn/Java/2137/

+3

Hello Shaikh Abdul. I see that you have tried using Command line arguments in your program. All the other people here are telling you to go for scanner class which is not wrong. Your program is correct. It's a method of adding two number without using the scanner class. Do not worry. Your program is completely correct. The only reason why your program isn't running is because the user inputs the number during run time. The sololearn online compiler isn't capable of taking run-time inputs since it's a virtual online compiler. If you have a pc with you with the jdk installed in your CMD then you can try your code. It will work fine. NOW looking closely at your program you can see that you have not declared the main method. Command line arguments will work. you just forgot to add the main method. Add the main method and try it on your pc not on online compilers. I repeat. Command Line Arguments Program will NOT RUN ON ONLINE COMPIlERS.

+2

Shaikh Abdul You need to take input using Scanner class like Scanner sc = new Scanner (System.in); a = sc.nextDouble();

+1

To accept values from user

+1

public class Add { public static void main(String[] args) { double a,b,c; System.out.println("Enter the first number"); a=Double.parseDouble(args[0]); System.out.println("Enter the second number"); b=Double.parseDouble(args[1]); c=a+b; System.out.println("The addition of two numbers is : "+c); } }

+1

This was the program

+1

+1

Thanks alot.. 😎👍

+1

Shaikh Abdul Without taking input from user how you can add different values. You can add only fixed value without scanner.

+1

Shaikh Abdul // Command Line Arguments means that you have to provide input during execution of program. compile by > javac Add.java   run by > java Add 10 20 Output : The addition of two numbers is 30. hope this helped.

0

Thank you very much .It is very helpful.. But why my code does not run?

0

Hey AJ is there any method to add two numbers without using scanner class?

0

Thats why i used wrapper class to take input from user..

0

public class Add { public static void main(String[] args) { double a,b,c; System.out.println("Enter the first number"); a=Double.parseDouble(args[0]); System.out.println("Enter the second number"); b=Double.parseDouble(args[1]); c=a+b; System.out.println("The addition of two numbers is : "+c); } } This is the code..And to give the inputs ..Open CommandPrompt go to current file directory .. javac (nameofprogram).java //Compilation javap Add(Class name) 10 20 // Execution

-1

Good day everyone. I need someone to help with what I can do. I was able to install Anaconda 3 on my System. Whenever try to work on the Jupyter Note, it will open but the code is not running, rather, the cursor will move to next line. I have to delete and reinstall but am still experiencing the same challenge. Any help will be appreciated.