Share on Google+

vinil pasupuleti
couldnt run this program
1 Answer(s)      4 years and 10 months ago
Posted in : Java Beginners

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");

Ads

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);
}
}
}
```

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
how to run rmi program
how to run rmi program  how to run rmi program
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
compile and run java program
compile and run java program  Hello, everyone!!! I just want to ask if you anyone here knows how to compile java file in linux specifically UBUNTU... do I compile and run this file using the terminal of ubuntu... By the way, I am
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
java program run on thml page?
java program run on thml page?  how to run java program on html page using text area
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
why java program not run with msword editor
why java program not run with msword editor  if java program write in MICROSOFT WORD then why they are not run with jdk
how to run jdbc program in linux-ubuntu?
how to run jdbc program in linux-ubuntu?   how to run jdbc program in linux-ubuntu
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 First Java Bean Program ?
How to Run First Java Bean Program ?  Hi My Dear Friend I can run... But Now I need that How to run Java Bean Now I have BDK1.1 But still don't know that how run this... I have this bdk dir... \bdk1_1\beans\beanbox
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
how to run jdbc in jsp program - JSP-Servlet
how to run jdbc in jsp program  i want to use sql server 2005 in jsp program to store data.i know how to run simple program but this program i tried my best i am not able to do so.please give me the answer of this as soon
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 Develop, Compile & Run a rmi Program in NetBeans 6.9.1 ide?
How to Develop, Compile & Run a rmi Program in NetBeans 6.9.1 ide?  how to develop, compile & run a rmi program in netbeans 6.9.1 ide? will you please give me a step by step (practical) explaination? Thanks in advance
New to JSP..need help to make & run a JSP program.
New to JSP..need help to make & run a JSP program.  Hi, I have installed Tomcat 5.5 on my system. Plz help me to make a simple JSP program. And also how to run it.   Hi Friend, Have you set the classpath? Anyways
Find the files that has been modified before run the program
modified a file in the directory and run the program, it can list out the file... and run the program, it can only show the file that has the latest modification time... i run the program?   Sorry. Please help me remove this post
Find the files that has been modified before run the program
in the directory and run the program, it can list out the file that i has been modified. But when i modified more then 1 files in the directory and run...Find the files that has been modified before run the program  Hi. I
Find the files that has been modified before run the program
in the directory and run the program, it can list out the file that i has been modified. But when i modified more then 1 files in the directory and run...Find the files that has been modified before run the program  Hi. I
run a java application - Java Beginners
\$1.class,SwingDemo\$2.class.But i couldnt run my file.During run time it gives...run a java application  Hai Deepak, I ve set my environment varibles(user variable) as CATALINA_HOME=C:\Program Files\Apache Tomcat 4.0
how to run java program that has several classes under package from usb drive?
how to run java program that has several classes under package from usb drive... package. I have to use following line on command line to compile and run my program... and run the code. I tried installing jdk but it was taking very long time so did
best os to run java
best os to run java  which is best os to run java program
j2me pgrm run
j2me pgrm run  How to run a j2me program   Please visit the following link: J2ME Tutorials
how to run - Java Beginners
how to run   how to run java program... brifely  Hi... the "javac" command to compile the program and after compiling,uses "java" command to execute or run the program. For ex, If you have the following java program
How to compile and run the JSP
How to compile and run the JSP  Hi Kindly tell me how to run and compile JSP small Program using Tomcat as webserver. I created small program HELLO JSP in HTML and compile the program but it is saying Class o r interface
java not run on my pc
java not run on my pc  i have installed java in pc but when i run and compile any program the massage is display that 'javac' is not recognized as an internal or external command
Run time problem
Run time problem  when i run a project,it shows an exception like "unable to create MIDlet".It also shows "running with locale:English_united......." program is import javax.microedition.lcdui.*; import
Tutorials

Ads

Advertisement null

Ads