0

request : make a simple basic java program using two methods

write a program which adds or subtract two number here are condition:- 1. make a method which will add two no. 2. make a method which subtract the two no. 3. ask user if they wanna add or subtract and then call the method needed as per need i am deeply confused and will really appreciate anyone who will make this basic script from which i can observe my mistake here is my code for reference if you need but it is not working :( __________________________________________________________________ package practice; import java.util.Scanner; public class sum { static Scanner input = new Scanner(System.in); public static double addition(double s1 ,double s2 ) { double sum1 = s1 + s2; return sum1; } public static double subtraction(double s1, double s2) { double sum1 = s1-s2; return sum1; } public static void main(String args[]) { double n1, n2, sum; System.out.println("welcome do you want to add or divide"); String s = input.next(); if (s.equalsIgnoreCase("add") || (s.equalsIgnoreCase("addition"))) { System.out.println("enter the two numbers"); n1 = input.nextDouble(); n2 = input.nextDouble(); sum = addition(n1, n2); System.out.println(sum); } else if (s.equalsIgnoreCase("minus") || (s.equalsIgnoreCase("subtraction"))) { System.out.println("enter the two numbers"); n1 = input.nextDouble(); n2 = input.nextDouble(); sum = subtraction(n1, n2); System.out.println(sum); } } } _________________________________________________________________________ [/code]

28th Mar 2019, 7:50 PM
kuku Debbarma
kuku Debbarma - avatar
1 Answer
+ 16
Remove : package statment Becz solo learn compiler does not support packages. So remove thats.
28th Mar 2019, 8:15 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar