couldnt run this program
package calculator;
import java.util.Scanner;
public class calculator{
public static void main(String args[]){
Scanner vin = new Scanner(System.in);
Double firstnum,secondnum,sum,sub,mul;
System.out.println("enter first number");
firstnum = vin.nextDouble();
System.out.println("enter second number");
secondnum = vin.nextDouble();
System.out.println("enter 1 for addition,2 for subtraction");
Double store=vin.nextDouble();
if(store==1){
sum=firstnum+secondnum;
System.out.println("sum is " + sum);
}
if(store==2){
sub=firstnum-secondnum;
System.out.println("sub is " + sub);
}
}
}print("code sample");
View Answers
June 15, 2012 at 10:55 AM
We have modified your code. The code accepts two numbers from the user and then ask for the calculation they want. According to that, it will perform operations i.e. addition and subtraction.
import java.util.*;
public class calculator{
public static void main(String args[]){
Scanner vin = new Scanner(System.in);
double firstnum,secondnum,sum=0,sub=0,mul;
System.out.print("Enter first number: ");
firstnum = vin.nextDouble();
System.out.print("Enter second number: ");
secondnum = vin.nextDouble();
System.out.print("Enter 1 for addition,2 for subtraction: ");
double store=vin.nextDouble();
if(store==1){
sum=firstnum+secondnum;
System.out.println("sum is " + sum);
}
if(store==2){
if(firstnum>secondnum){
sub=firstnum-secondnum;
}
else if(secondnum>firstnum){
sub=secondnum-firstnum;
}
System.out.println("sub is " + sub);
}
}
}
Ads
Related Tutorials/Questions & Answers:
couldnt run this program
couldnt run this program package calculator;
import java.util.Scanner;
public class calculator{
public static void main(String args[]){
Scanner vin = new Scanner(System.in);
Double firstnum,secondnum,sum,sub,mul
Advertisements
how to run this program?
how to
run this
program? how to
run java swing
program
Java Swing
program runs same as a simple java
program. There is no difference... with javac and
run with java command, same as a simple java
program.
Learn Swing
how to run java program
how to
run java program i have jar file.
in jar i have so many classes.in one of file i want modify .after modifying file i want replce in jar.
please help me to how to generate class and how to replace
How to run JSP program inEclipse?
How to
run JSP
program inEclipse? Hi,
I am learning JSP. I want to
run JSP in Eclipse.
How to
run JSP
program inEclipse?
Thanks
Hi,
Its easy to
run JSP from the Eclipse. You have to make a dynamic web application
How to compile and run Java program
How to compile and
run Java program How to compile and Java
program...,
For compiling and running the Java
program from command prompt you should must have JDK... tutorial
Compiling and Running Java
program from command line.
If Java
how to compile and run servlet program
how to compile and
run servlet
program hello sir/mam i hve installed tomcat5.5 version and also have jdk1.6.0_14 installed but not able to
run it or compile i m doing it first tyme pls help me in sorting out this problem.
i hve
How Jdbc program can be run??
How Jdbc
program can be
run?? import java.sql.*;
import java.util.... created successfully and
when i compiled this
program then it compiled successfully ,but when i
run it ,it gives following error->
C:\
Program Files\Java
How to run program in new opened cmd
How to
run program in new opened cmd Hello i have made a
program in java to open command prompt, then how to
run my left of the
program in the new opened command prompt
how to run a java program using run.exec()?
how to
run a java
program using run.exec()? Hi..i want to compile and
run a java file using run.exec().i.e., without compiling and running from command prompt i want to do them in the
program itself.I am able to compile
how to run jdbc program in linux-ubuntu?
how to
run jdbc
program in linux-ubuntu? how to
run jdbc
program in linux-ubuntu?
hi
firstly download the jdk on your system using... to compile java
program
javac prog.java
java prog
run command prompt from jsp program
run command prompt from jsp program Hi....
Is it possible to
run a command prompt from jsp? If possible please help me with some code...
Thanks & Regards
vanchinathan.R
How to run a Java program in CMD
There are multiple ways to write and
run Java programs. In this article we
discussed how to write and
run Java
program in CMD.
Tips to
run Java
program... it should compile the
file.
Now time to execute the
program.
Run
How to run JSP program in Tomcat server step by step?
How to
run JSP
program in Tomcat server step by step? Hi,
I am trying to
run the JSP and looking for the quick example that will teach me to
run....
How to
run JSP
program in Tomcat server step by step?
Thanks
Hi
program
program write a javascript
program to create a application form with validation
program
program write a html
program in show table and this word
in box
program
program write a
program different between to dates in terms of days in java
program
program write a
program reversee a string.
input-hi this is roseindia
output-roseindia is this hi
program
program develop a servlet to insert the data in the database from our
program in the table stored in the database
program
program WAP a java
program to form 1/2+3/4+5/6+7/8 series
program
program write a java
program to input a no. and print wheather the no. is a special no or not. (special no. are those no whose factorial of the sum of digit of the no is same as the original
program
program how to improve programming skills plss tell some tips..i am understanding concepts but unable to write
program so,pls give some guideness plsss
Program
Program a
program to prove that default constructor of super class is available to subclass by default. Define a parameterize constructor for super class to store name = â??Tommyâ?? age=â??23â?? and call this constructor