How to Multiply Two Multi-Digit Integers in Java

The Java Programming language was born from the notion of building a cross-platform, object-oriented language influenced by the syntax of C. Thus Java can and does perform many of the same functions as C, with a fully realized object-oriented data hierarchy. That being said, even basic operations like multiplication can be performed in Java, and serve as the foundation for its functionality.

Things You'll Need

  • Java Development Kit
  • Text editor
Show More

Instructions

    • 1

      Set up a multiplication class, which will be the main program in this example:

      class Mult{
      public static void main(String[] args){

      }
      }

    • 2

      Declare two variables that contain multidigit integers in the main method:

      public static void main(String[] args){

      public int x = 567;
      public int y = 789;

      }

    • 3

      Multiply the two integers using the * operator:

      public static void main(String[] args){

      public int x = 567;
      public int y = 789;

      public int z = x * y; // z = 447, 363
      }

    • 4

      Create a larger integer. Normal integers in Java have a maximum value of 2,147,483,647. To multiply larger numbers, use the long data type, which represents a maximum value of 9,223,372,036,854,775,807:

      public static void main(String[] args){

      public long x = 95678;
      public long y = 96789;

      public long z = x * y; // z = 9,260,577,942
      }

Related Searches:

References

Comments

Related Ads

Featured