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









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 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
Advertisements
how to run rmi program
how to run rmi program  how to run rmi program
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..._TO_REPLACE_1 how do I compile and run this file using the terminal of ubuntu
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 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-> (adsbygoogle
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 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
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 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
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
discussed how to write and run Java program in CMD. Tips to run Java program... the program. Run the given command. C:\myproject> java HelloWorldADS_TO_REPLACE_2 This will run the Java interpreter and You will see the program output
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
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.ADS_TO_REPLACE_1   Hi Friend, Have you set
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
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
program
program  any program of hotel or school management
program
program  program of jdbc using ms access for creating table
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  WAP a java program to form 1/2+3/4+5/6+7/8 series
program
program   Write a program to find the difference between sum of the squares and the square of the sums of n numbers
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   An old-style movie theater has a simple profit program. Each customer pays $5 per ticket. Every performance costs the theater $20, plus $.50 per attendee. Develop the program calculateTotalProfit that consumes
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  Develop the program calculateCylinderArea, which accepts radius of the cylinder's base disk and its height and computes surface area of the cylinder
program
program  explanation of program on extending thread class   Hi Friend, Please go through the following link:ADS_TO_REPLACE_1 Java Threads Thanks
program
program  Develop a program that computes the distance a boat travels across a river, given the width of the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time, and the Pythagorean
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
Program
Program  a program to create two classes Commercial and Domestic. Override the method calculatebill() of Commercial class(Rs.8 per unit) into Domestic class(Rs 6 per unit) to compute electricity bill for both classes
program
program  no i want a program that shows how merge sort algorithm works in graphical representations like numbers are taken in circles and computation... in rectangles or circles wat ever it may be. the theme of program is to show algorithm
program
program  . Develop a program that accepts an initial amount of money (called the principal), a simple annual interest rate, and a number of months will compute the balance at the end of that time. Assume that no additional
program
program  Write a JSP Program, which displays a web page containing the name of the Courses, Courses being offered currently, number of students enrolled in each course, new courses to be offered, eligibility criteria for taking
program
program  i want a progra in java to print a sentence in alphabetic order, taking the input from the user.the program should writen without using the array for example : if input= this is a cat then output sould = a cat
program
program  Write a JSP Program, which displays a web page containing two web links one for your profiling and other for the schedule of theory of practical classes of your Batch. When one click on link for getting your profile
program
program  Write a program to print details of a week for a particular day using array of objects Integer and String. OUTPUT: First Day of Week is Monday Second Day of Week is Tuesday Third Day of Week is Wednesday Forth Day

Ads