couldnt run this program

Ads
 

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
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
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 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 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 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 run jdbc program in linux-ubuntu?
how to run jdbc program in linux-ubuntu?   how to run jdbc program in linux-ubuntu
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 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 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
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
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
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
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

Ads