- 1

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 input 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 but it is not working :( [code] 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:49 PM
kuku Debbarma
kuku Debbarma - avatar
1 Resposta
0
Don't know if this is still relevant but you might receive useful answers if you publish your code on the playground and link it here.
25th Feb 2020, 3:45 PM
Tashi N
Tashi N - avatar