Integer Division and Modulus to Isolate Digits in an Integer
Not what you're looking for?
Given a large number we sometimes need to extract individual digits or sequences of digits from it. For example, given a four-digit year (2010) we may need to extract just the two-digit year or the century. The mathematical operators modulus (Java: %) and division (Java: integer division /) help us with this. Using the operators % and / write the Java expression that will extract the following:
From 2010 extract the 10 and the 20
From 98765432 extract the middle three digits (765)
From 153 extract each individual digit (1, 5, 3)
Write your solution in a simple text file.
Purchase this Solution
Solution Summary
This solution explains how to use the % and / operators to isolate individual digits in an integer. These examples help to solidify the arithmetic concepts behind these two operators. 178 words.
Solution Preview
The % and / operators will help us isolate individual digits out of the larger number. The % operator will return the remainder after doing the division. If we use the modulus operator with a power of 10 (i.e., 10, 100, 1000, etc.) then the result will be ...
Purchase this Solution
Free BrainMass Quizzes
Javscript Basics
Quiz on basics of javascript programming language.
C++ Operators
This quiz tests a student's knowledge about C++ operators.
C# variables and classes
This quiz contains questions about C# classes and variables.
Word 2010: Tables
Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.
Word 2010: Table of Contents
Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.