Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JavaScriptQuestions Write a program in java...

Have Programming Question? Ask it here!
 
 
 


MrScorpion
Write a program in java...
1 Answer(s)      3 years and 3 months ago
Posted in : JavaScript Questions


Hi, friends

Please, can you help me?

Q1: Write a program in java to simulate a calculator. Your program should take two numbers and an operator(+,-,*,or/), from the user in the following format: number1 operator number2 (For example 2 + 4) and print the result.Take all variables used in the program of type double.

Your program should work as long as a user wishes. Print the result up to two places of decimal.

Q2: Ask the user to enter an integer number. Write a program in java to find the factorial of a non negative integer number.

Factorial of a number is dfined as :

n! ={ 1 =======> if n = 0 , (n-1)! x n ======> if n > 0 }

(For Example 0!=1 and 1!=1 and 2!=1*2=1)

Thank you for reading :)


Advertisement
View Answers

May 16, 2011 at 10:51 AM


1)

import java.util.*;
public class Calculate {

       public static void main(String[] args) {
          Scanner input=new Scanner(System.in);
          double num1;    
          double num2;   
          char operator;      
          double result;       

          System.out.println("Enter expressions such as  17 + 3 or 3.14159 * 4.7");
          System.out.println("Use any of the operators +, -, *, /.");
          System.out.println("To end, enter a 0.");

          while (true){
              System.out.println();
              System.out.println("Enter Expression: ");
              num1 = input.nextDouble();
              if (num1 == 0)
                 break;
              operator = input.next().charAt(0);
              num2 = input.nextDouble();

              switch (operator) {
                  case '+':
                     result = num1 + num2;
                     break;
                  case '-':
                     result = num1 - num2;
                     break;
                  case '*':
                     result = num1 * num2;
                     break;
                  case '/':
                     result = num1 / num2;
                     break;
                  default:
                    System.out.println("Unknown operator: " + operator);
                     continue;  
              } 
          System.out.println("Result is " + result);
        }
      } 
    }

2)

import java.util.*;
class  Factorial{
    public static void main(String[] args) 
    {
        Scanner input=new Scanner(System.in);
        System.out.print("Enter value of m: ");
        int m=input.nextInt();
        long num=m;
        for(int i=m;i>1;i--){
            num=num*(i-1);
        }
        System.out.println(num);
    }
}


Related Tutorials/Questions & Answers:
write a java program
write a java program  write a program to print '*' in a circular form
How to write Java Program
How to write Java Program  how to write a program to find average of 5 student marks
Advertisements
write the java program?
write the java program?  1 11 121 1331 14641 15101051
write the java program?
write the java program?  1 11 121 1331 14641 15101051
Write java program?
Write java program?  1 11 121 1331 14641 15101051
Write java program?
Write java program?  1 11 121 1331 14641 15101051
Write a java application program........?
Write a java application program........?  Welcome every One : I have Q in Java? Q : Write a java application program that reads 20 integer numbers input by the user and prints how many numbers > 100 and how many numbers
Write a program in java...
Write a program in java...  Hi, friends Please, can you help me? Q1: Write a program in java to simulate a calculator. Your program should take two... to enter an integer number. Write a program in java to find the factorial
WRITE A PROGRAM IN JAVA
WRITE A PROGRAM IN JAVA  Write program which accepts five students id,name,age,department,courses, taken and its grade. a. calculate its GPA . display all student information in ascending order
WRITE A PROGRAM IN JAVA
WRITE A PROGRAM IN JAVA  How do I write a program in Java, have the program display a message with your name in it and a number (Hello john Smith!1) The number must increment from zero to nine, or decrement fron nine to zero. You
write program - Java Beginners
write program  write a java program that will read the values...]); } System.out.println(); } } } For more information on java visit to : http://www.roseindia.net/java/beginners/ Thanks
write a program - Java Beginners
write a program  1. write a program that reads a string composed of 6 words then generate and print a word composed of the first letters of the 6 words.  Hi friend, Code to solve the problem : class FirstLetter
write a program in java.
write a program in java.  arrange the natural n umber in 5x5 matrix as 21 22 23 24 25 20 7 8 9 10 19 6 1 2 11 18 5 4 3 12 17 16 15 14 13 i at centerd position and remaining arrange in anticlockwise direction.  
how to write this program? - Java Beginners
how to write this program?  (game:scissor,rock ,paper) A program that plays the sciccor-rock-paper game.Revise the program to let the user continuously play until either the user or the computer wins more than 4 times
how to write the program - Java Beginners
how to write the program  WAP to create the report card user input Name, Class, Division, Roll no., Marks obtained in following subjects Lang Hindi History Geography Math Phy Chem. Bio Eve CSTA Also has a back up
write a program
write a program  write a program add 2 no.s without use arithmetic,unary operaters in java
write a java program to solve the infix expression
write a java program to solve the infix expression  ==>> solve the below expression using java program: 2+5*2-5+6/2 using stack operations or any other process in java
Help me to write this simple java frame program
Help me to write this simple java frame program   I want to write a Java program for.... To create a frame with 4 text fields;name,street,city and pin;with suitable labels. Also add a button "OK". After enter values
Write a java program that prints out the following menu???
Write a java program that prints out the following menu???  Write a java program that prints out the following menu. Auser can interact with the menu using numbers (1,2,3,4,5,6). The menu will be printed again if the user enters
how do i write a java program for this??
how do i write a java program for this??  â??Ask the user if they have a dog. If â??yesâ??, ask the user how old is and compute the dogâ??s age... in your program
write a java program that implements the following classes:
write a java program that implements the following classes:  write a java program that implements the following classes: A) a) Point in the Cartesian coordinate system. b) Circle with a given center and radius c) Cylinder
Please write code for this program in java and Explain it ? pl'sssssssss
Please write code for this program in java and Explain it ? pl'sssssssss ... that were ever alive at one time. Write a method to compute this, given the above array of 2n integers. Write one of the following methods: C/C++: int
Write a program in Java to append content at the end of an already existing file.
Write a program in Java to append content at the end of an already existing file.  Write a program in Java to append content at the end of an already existing file
write a java program for pagination which will be configured by end user
write a java program for pagination which will be configured by end user  write a java program for pagination which will be configured by end user
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?
write a program in java to read a text file and write the output to an excel file using filereader and filewriter?  write a program in java to read a text file and write the output to an excel file using filereader and filewriter
write a java program for pagination which will be configured by end user
write a java program for pagination which will be configured by end user  write a java program for pagination which will be configured by end user...;Java
Write a java program to display the season given the month using switch case
Write a java program to display the season given the month using switch case  Write a java program to display the season given the month using switch case
write a program in java to demonstrate the complete life cycle of servlet:
write a program in java to demonstrate the complete life cycle of servlet:  l have an assignment question. i don't know how to write the code for this program. my question is :Write a program in Java to demonstrate the complete
How to Write a Calculator Program in Java?
How to Write a Calculator Program in Java? In this Java Tutorial you will learn how to write a Calculator program in Java in easy steps. Calculator program..., subtraction, multiplication or division. In this example of writing program in Java
How to write program to show status of seats(i.e.free or reserve) in java?
How to write program to show status of seats(i.e.free or reserve) in java?  I have retrieved data from database table and I want to display status of seats i.e.free or reserved
Write a program that converts any given year to Roman Numeral in Java
Write a program that converts any given year to Roman Numeral in Java  Write a program that converts any given year to Roman Numeral
how to write to java program to get the particular data from the website
how to write to java program to get the particular data from the website   i have to get the particular data by selecting the just numbers.. from the site .. how to get the ful details from the website by clicking the number
how to write a program in java to print numbers in equalateral triangle
how to write a program in java to print numbers in equalateral triangle  the output must be 1 324 76589   Here is an example of pattern 1 2 3 4 5 6 7 8 9 Example: public class NumberTriangle{ public
how to write this program
how to write this program  Write a program in java which calculates... or numerical grade. You will be submitting TWO versions of this program. Write one...?˘s GPA. This program should take a studentââ?¬â?˘s First Name, Last Name a GPA
write a program to print
write a program to print   write a program to print following 1 2 3 4 5 4 3 2 1 1 2 3 4 4 3 2 1 1 2 3 3 2 1 1 2 2 1 1 1
write following program
-threading. Explain with examples Q2 Write a java applet that takes your name... the state transition diagram of a thread Q6 Write a java applet that displays 9... is a java applet? Write a java applet to display "Hello JAVA". Also write the relation
Write a java program that prints the decimal representation in reverse. (For example n=173,the program should print 371.)c
Write a java program that prints the decimal representation in reverse. (For example n=173,the program should print 371.)c  class rose { int n; int i; rose(int n,int i) { n=173; i=371; } void out { System.out.println
how to write servlet program in eclipse?
how to write servlet program in eclipse?  how to write servlet program in eclipse
How to write calculator in J2ME program?
How to write calculator in J2ME program?  How to write calculator in J2ME program
Write a program to print using for loop
Write a program to print using for loop  Write a program to print using for loop * * * *  
write a java program for inserting a substring in to the given main string from a given position
write a java program for inserting a substring in to the given main string from a given position  write a java program for inserting a substring in to the given main string from a given position
to write a program to display the employee details..
to write a program to display the employee details..  To dipslay the employee details like empid,empname,salary,wonno bye using java swings.by running this program the new window has to be opened asking us to enter all
Write a program in JAVA which accepts a sentence & displays the longest word in the sentence alongn with it length of the word.
Write a program in JAVA which accepts a sentence & displays the longest word in the sentence alongn with it length of the word.  **A program in JAVA which accepts a sentence & displays the longest word in the sentence along
write a java program to print marklist of "n " students. input Register number, name and marks of three subjects.
write a java program to print marklist of "n " students. input Register number, name and marks of three subjects.  write a java program to print marklist of "n " students. input Register number, name and marks of three subjects
To write a Java program To create a frame with 4 fields;name,street,city,pin;with suitable table
To write a Java program To create a frame with 4 fields;name,street,city,pin;with suitable table  I want to write a Java program To create... to be appeared in text field Can someone write a program for the above? I have
Java Write To File - Java Tutorial
on a FileOutputStream classes to write data to a file from Java program... of Java Tutorial you will learn how to write java program to write to a file. We..., arrays, and strings. Here is the code of java program to write text to a file
write a program to create a user defined
write a program to create a user defined   plz send me code   Hi Friend, Please specify what do you want to create? Thanks
really need help on how to write this program plz some 1 help out. - Java Beginners
really need help on how to write this program plz some 1 help out.  i am confused here on what to write can some 1 help out here i dont quite... a Java program that displays the following prompts: Enter
Write a java program that encrypt and decrypt some string by adding or removing 2 on each character.
Write a java program that encrypt and decrypt some string by adding or removing 2 on each character.  Write a java program that encrypt and decrypt some string by adding or removing 2 on each character. Example 1 : Please Enter
How can I write a GUI stack program by Java to push Image files instead of other data type items?
How can I write a GUI stack program by Java to push Image files instead of other data type items?   How can I write a GUI stack program by Java to push Image files instead of other data type items? for the push instruction I
Advertisements
 

 

 

DMCA.com