Arithmetic Demo : Data Type Number « Language Basics « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Language Basics » Data Type NumberScreenshots 
Arithmetic Demo
Arithmetic Demo

/* From http://java.sun.com/docs/books/tutorial/index.html */
/*
 * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * -Redistribution of source code must retain the above copyright notice, this
 *  list of conditions and the following disclaimer.
 *
 * -Redistribution in binary form must reproduce the above copyright notice,
 *  this list of conditions and the following disclaimer in the documentation
 *  and/or other materials provided with the distribution.
 *
 * Neither the name of Sun Microsystems, Inc. or the names of contributors may
 * be used to endorse or promote products derived from this software without
 * specific prior written permission.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN")
 * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
 * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
 * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
 * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 *
 * You acknowledge that this software is not designed, licensed or intended
 * for use in the design, construction, operation or maintenance of any
 * nuclear facility.
 */
public class ArithmeticDemo {
    public static void main(String[] args) {

        //a few numbers
        int i = 37;
        int j = 42;
        double x = 27.475;
        double y = 7.22;
        System.out.println("Variable values...");
        System.out.println("    i = " + i);
        System.out.println("    j = " + j);
        System.out.println("    x = " + x);
        System.out.println("    y = " + y);

        //adding numbers
        System.out.println("Adding...");
        System.out.println("    i + j = " (i + j));
        System.out.println("    x + y = " (x + y));

        //subtracting numbers
        System.out.println("Subtracting...");
        System.out.println("    i - j = " (i - j));
        System.out.println("    x - y = " (x - y));

        //multiplying numbers
        System.out.println("Multiplying...");
        System.out.println("    i * j = " (i * j));
        System.out.println("    x * y = " (x * y));

        //dividing numbers
        System.out.println("Dividing...");
        System.out.println("    i / j = " (i / j));
        System.out.println("    x / y = " (x / y));

        //computing the remainder resulting from dividing numbers
        System.out.println("Computing the remainder...");
        System.out.println("    i % j = " (i % j));
        System.out.println("    x % y = " (x % y));

        //mixing types
        System.out.println("Mixing types...");
        System.out.println("    j + y = " (j + y));
        System.out.println("    i * x = " (i * x));
    }
}

           
       
Related examples in the same category
1. Max Variable Length DemoMax Variable Length Demo
2. Data Type Print TestData Type Print Test
3. Tests all the operators on all the primitive data types
4. Demonstrates the ++ and -- operatorsDemonstrates the ++ and -- operators
5. Literals
6. Demonstrates the mathematical operators.Demonstrates the mathematical operators.
7. Java lets you overflowJava lets you overflow
8. Cast a float or double to an integral valueCast a float or double to an integral value
9. Built in typesBuilt in types
10. A simple casting demo
11. This shows something interesting about addition of byte variablesThis shows something interesting about addition of byte variables
12. Boolean And Or
13. Char is IntChar is Int
14. Class Casting DemoClass Casting Demo
15. Are all hex integers negativeAre all hex integers negative
16. LengthOf - show length of things
17. Shorts Vs IntsShorts Vs Ints
18. Casting Demo
19. A class to represent Complex Numbers
20.  Get Double Number
21. Compute the value of 2/3 of 5Compute the value of 2/3 of 5
22. Floating-point comparisonsFloating-point comparisons
23. Float Double Time Float Double Time
24. Int OverflowInt Overflow
25. Multiply a decimal fraction, not using floating pointMultiply a decimal fraction, not using floating point
26. Show INFINITY and NaN
27. Format a number our way and the default way
28. Parse a number using a NumberFormat
29. Compute the Palindrome of a number by adding the number composed of
30. Compute prime numbers
31. Demonstrate the better way of getting random numbers 3
32. Demonstrate the better way of getting random numbers 2
33. Demonstrate the better way of getting random numbers
34. Generate random ints by asking Random() for
35. Number Format Test Number Format Test
36. Shows default initial valuesShows default initial values
37. Downcasting and Run-Time Type Identification (RTTI)
38. Relational DemoRelational Demo
39. Demonstration of high-precision arithmetic with the BigDouble classDemonstration of high-precision arithmetic with the BigDouble class
40. Demonstration of high-precision integer arithmetic with the BigInteger classDemonstration of high-precision integer arithmetic with the BigInteger class
41. Floating-pioint error diagnostics
42. Obtaining the integer and fractional parts
43. Floating pioint comparisons
44. Value Of Demo
45. Float compare to Float compare to
w___w_w__.___j__a__v_a2__s_.__c__o___m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.