# java

Raghavendra
java
1 Answer(s)      6 years and 4 months ago
Posted in : Java Beginners

Code a class that can be used to add, multiply, divide, get remainder, subtract two input numbers. Perform all kinds of boundary checks to ensure there is no overflow. (use wrapper classes to get constants to check against). Also add functionality to get the squareroot, log, round, ceil, floor of the input number.

July 5, 2011 at 3:44 PM

```import java.util.*;

public class Calculate {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Num1: ");
double num1 = input.nextDouble();
System.out.print("Num2: ");
double num2 = input.nextDouble();
if (num1 > 0 && num2 > 0) {
double sum = num1 + num2;
System.out.println("Sum= " + sum);
double diff = 0;
if (num1 > num2) {
diff = num1 - num2;
} else {
diff = num2 - num1;
}
System.out.println("Difference= " + diff);
double prod = num1 * num2;
System.out.println("Product= " + prod);
double rem = num1%num2;
System.out.println("Remainder= " + rem);

double div = num1/num2;
System.out.println("Division= " + div);

double sr1=Math.sqrt(num1);
double sr2=Math.sqrt(num2);
System.out.println("Square root of num1= " + sr1+" and num2= "+sr2);

double log1=Math.log(num1);
double log2=Math.log(num2);
System.out.println("Log of num1= " + log1+" and num2= "+log2);

double round1=Math.round(num1);
double round2=Math.round(num2);
System.out.println("Round-of of num1= " + round1+" and num2= "+round2);

double ceil1=Math.ceil(num1);
double ceil2=Math.ceil(num2);
System.out.println("Ceil of num1= " + ceil1+" and num2= "+ceil2);

double floor1=Math.floor(num1);
double floor2=Math.floor(num2);
System.out.println("Floor of num1= " + floor1+" and num2= "+floor2);

} else {
System.out.println("Invalid Numbers");
System.out.println("End of program");
}
}
}
```

java
java  diff bt core java and java
java
java  what is java
JAVA
JAVA  how the name came for java language as "JAVA
java
java   why iterator in java if we for loop
java
java  explain technologies are used in java now days and structure java
java
java  different between java & core java
Java
Java   Whether Java is pure object oriented Language
java
java  is java open source
java
java  what is java reflection
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java   What is ?static? keyword
java
java  RARP implementation using java socket
java
java  sample code for RARP using java
java
java  Does java allows multiline comments
Java
Java  how to do java in command prompt
java
java  give a simple example for inheritance in java
java
java  give a simple example for inheritance in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  Write a java code to print "ABABBABCABABBA
java
java  write a program in java to acess the email
java
java  send me java interview questions
java
java  how use java method
java
java  what are JAVA applications development tools
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  is java purely object oriented language
java
java  why multiple inheritance is not possible in java
java
java  explain object oriented concept in java