Home Answers Viewqa Java-Beginners couldnt run this program

 
 


vinil pasupuleti
couldnt run this program
1 Answer(s)      a year 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");

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 Pages:
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
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 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 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 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
best os to run java
best os to run java  which is best os to run java program
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
j2me pgrm run
j2me pgrm run  How to run a j2me program   Please visit the following link: J2ME Tutorials
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
how to run applet - Applet
how to run applet   Hi everybody i am using connecting jdbc in applet program. this is executed successfully with appletviewer command >appletviewer -J-Djava.security.policy=A0.txt A0.html but cannot in browser
java pages run
java pages run  how do we run jsp file in the browser. do we need to install server. could it be run on the xamp server   You need Apache Tomcat Server to run the jsp code over it. Follow these steps to run the simple
run time error
run time error  my program compile successfully but does not showing output for any program ...   Post your code.   public class...("Hello, World!"); } } // This is simple program but after successful compiles
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
how to run servlet - JSP-Servlet
how to run servlet  pls give me comlete procedure to run the servlet on apache-tomcat 6.0.16 how can i set my classpath, java_home etc. also where i have to save my servlet program and how it compile and then run on web browser
not able to run in gcj file - JDBC
not able to run in gcj file   We have a java program in Linux... to run the java program it says that Classes12.Jar?s oracle Driver missing. We... the GCJ compiled Java Program. ?./Test? When we tried the same program
How to run a servlet
How to Run a Servlet       To run a servlet one should follow the steps illustrated below:  Download... as Variable Name:  CLASSPATH  Variable Value:  C:\Program Files
HOW TO RUN JDBC PRORAM ON JDK1.5.0
HOW TO RUN JDBC PRORAM ON JDK1.5.0  import java.sql.*; import... this program i am using jdk1.5.0`*print("code sample");*` I have created Dsn Successfully ,table also has been created successfully and when i compiled this program
java run time error - JDBC
java run time error  when i m running for batch execution program in jdbc i m facing this kind of runtime error as Exception in thread "main" java.sql.SQLException: Io exception: The Network Adap ter could not establish
how to compile and run struts application - Struts
how to compile and run struts application  how to compile and run struts program(ex :actionform,actionclass) from command line or in editplus 3
Threads(suspend(),resume()) run time abnormal behaviour
Threads(suspend(),resume()) run time abnormal behaviour   class...=new Thread(this); t.start(); } public void run..."); a1.t.resume(); } } hi! when i run this code after some seconds
java run time error - Java Beginners
java run time error  when i compile my program it didnt show any error in my program.but i cant run my program, if i run my program means it will show error like as following Exception in thread "main
java run time error in loading the driver - JDBC
java run time error in loading the driver  when i mrunning the program in oracle using type 4 driver it is giving the error as Error:jdbc.driver.OracleDriver the code was as follows: please suggest me how it can
error in java progran at run time - Java Beginners
error in java progran at run time  Hello sir,,, i make a servlet program in java,,but i face some problem,,so please me.. Actually this type of error are come in my all servlet program My Servlet-- Error
error in java progran at run time - Java Beginners
error in java progran at run time  Hello sir,,, i make a servlet program in java,,but i face some problem,,so please me.. Actually this type of error are come in my all servlet program My Servlet-- Error
How to run a simple jsp page in tomcat???
How to run a simple jsp page in tomcat???  i am trying to run...;yes...i did. i.e SET CLASSPATH=.;C:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar using this ,i am able to run all servlet programs
java applet run time error - Applet
java applet run time error  Hi, Im new to java applet.please help me. i have create a MPEG movie player in applet. when i run that program it show the error that,"javax.media.NoPlayerException: Error instantiating class
java run time error - Java Beginners
java run time error  i am getting error "main" java.lang.NullPointerException" in my program, iam sending code actually motive of program....... please correct my program, tell me where the problem occurs and what should
JSP and Servlet did not run - JSP-Servlet
JSP and Servlet did not run  I tried to run this program but when I clicked submit button it give me; HTTP Status 404- and did not give me display what I wanted. Anyone can trace what I made wrong here
Unable to run the jsp page - JSP-Servlet
Unable to run the jsp page  Expert:Naga Hi, I need solution this program. In cart.jsp I printed the total amount of the products then the next page is shipping and billing details and the next page is payment details. What
Abut Deploying and Developing Web-Logic in JDK1.5 version to run the EJB
and run the Web-Logic in JDK1.5 version. And can we have Tomcat installed in the system simultaneously with the Web-Logic.Kindly tell to run a simple EJB program...Abut Deploying and Developing Web-Logic in JDK1.5 version to run the EJB 
j2me program
j2me program  how to run j2me program?what setting is to do whem we run j2me programs?   Please go through the following link: J2ME Tutorials
How to run java swing application from jar files .
How to run java swing application from jar files .  Hello Sir... setup file .As per my knowledge i have to run .jar file from dist folder of netbeans but when i am trying to run from there i am getting error "Could not find
How Run JSP in Apache TomCat Server? - JSP-Servlet
How Run JSP in Apache TomCat Server?  How to Run JSP in Apache Tomcat Server? I have getting Jasper Exception which says class not found i have... program there. You can also check compete tomcat tutorial at http
java program
java program  write an error.jsp , which will be called in case there will be any run time error in the system , page crash