© Ron Dai 2019
R. DaiLearn Java with Mathhttps://doi.org/10.1007/978-1-4842-5209-3_1

1. Introduction

Ron Dai1 
(1)
Seattle, WA, USA
 

There are many good Java programming books on the market, but it is not easy to find one fit for a beginner who is new to Java and has minimal programming knowledge.

This book will help beginners learn how to effectively program in Java. My intent is to simplify the more complex aspects of Java and to guide the learner in exploring things “under the hood.” I hope the instructions inside this book are intuitive enough for readers to follow through with hands-on practice.

People who have experience with programming understand that mathematical knowledge plays a crucial role in programming design. So having a good foundation of math skills is undoubtedly super helpful when learning programming. This book provides a good opportunity to practice mathematical problem solving in a programming context. With this motivation in mind, I have included some math practice problems applicable to programming-related concepts.

Learning with deliberate practice enhances your understanding of new concepts on a deeper level. Actively participating in hands-on projects is a critical part of the learning process. And more practice will lead to producing results more quickly. I hope this will be an enjoyable learning experience for you.

Programming work involves designing and writing code using a certain computer language. Correctly executed code will perform repetitive tasks and accomplish expected goals. Nowadays, as high-technology products are being integrated into our daily lives, computer programming skills are becoming indispensable almost everywhere. Many daily computation jobs have already been replaced by programmed devices–you don’t need to look further than the self-checkout line at your local supermarket or the ever-increasing number of products purchased online. Reoccurring events are increasingly controlled by automated systems, such as building security system, thermostats mounted on the walls inside your house, and a plethora of other examples.

Another example is gaming software, which has such a rich user interface that many of us—from teenagers to adults—are already addicted to it. All these products and services are essentially built by computer programming.

As the beauty of artificial intelligence emerges, we can already see and feel the power of applications of computer technology more than ever before. If you have watched Hollywood movies like Arrival or Passengers (both released in 2016), I am sure you were fascinated by the amazingly intelligent robots depicted in the movies. If you are curious how a computer can precisely recognize an object with an activity in any picture, I suggest you listen to an exciting TED Talk named “How We Teach Computers to Understand Pictures” All of these amazing things are empowered by software, which is written in programming language(s).

To become a good programmer, you need to understand logical control and basic counting methods. It will require more sophisticated math knowledge if you want to develop a system to control objects’ activities.

There are quite a lot of famous but unsolved problems in math history. As computer technology improves, we can leverage computers’ talents to solve some of these problems.

For example, the Collatz conjecture states that if you randomly pick a positive integer N, and if it is even, divide it by 2; if it is odd, multiply it by 3 and add 1. And if you repeat this procedure long enough, eventually the end result of N will always be 1.

Mathematicians and data researchers have tried millions of numbers. No exception has been found, but no one has found a way to prove all integers following this rule.

Using simple Java programming, we can prove the Collatz conjecture for any positive integer up to N. In the following short program, I will test the conjecture with every integer and find out its sequence length, which is the number of operations for it to reach the result “1.”
public class ProveIt {
        public static void main(String[] args) {
                // representation of a million
                final long N = 1000 * 1000;
                for(long i = 1; i <= N; i++) {
                        System.out.println("i=" + i + " - " +
                                GetCollatzSequenceCount(i));
                }
                System.out.println("DONE!");
        }
        private static long GetCollatzSequenceCount(long n) {
                if (n <= 0) return 0;
                long count = 0;
                while(true) {
                        if (n == 1) return count;
                        if (n % 2 == 0) {
                                n /= 2;
                        } else {
                                n = n * 3 + 1;
                        }
                        count++;
                }
        }
}

Guess what? To test up to 1,000,000 integers, it completes executions and reports results back within several seconds on a normal work laptop. Don’t worry about understanding or running this code now; just appreciate that this short program can churn through 1,000,000 iterations in only a few seconds.

The last part of the output is:
i=999991 - 165
i=999992 - 113
i=999993 - 165
i=999994 - 113
i=999995 - 258
i=999996 - 113
i=999997 - 113
i=999998 - 258
i=999999 - 258
i=1000000 - 152
DONE!
One last thing to mention about notation in this book:
  • Math: describes a specific math concept.

  • Problems: provides a list of follow-up exercises. You can find hints for some problems.

  • Hint: suggests ideas for references to solve the problem.

  • Finally, students are encouraged to try Lab Work, after learning Answer and Example.

Problems

  1. 1.
    List an example that you have observed about something satisfying both (a) and (b) described as below.
    1. (a)

      There is no programming feature associated with it now.

       
    2. (b)

      It will function much more efficiently if there is a program built in it.

       
     
  2. 2.

    How do we exchange different types of water between the two cups?

     
You are not allowed to mix the water.
  1. 3.

    I am thinking about an integer between 1 and 100. You may ask me questions in order to identify the integer, but you are not allowed to ask questions like “what is this integer?”

     
What is your strategy to ask the minimum number of questions in order to figure out the number?
  1. 4.

    There are 27 ping pong balls. All of them look identical and weigh the same, except that one of them is lighter. Using a balance scale, how do you quickly find the one that is not the same as the others?

     
  2. 5.

    How do you use the following four numbers with basic operators (“+” , “-” , “x” , and “/”) to create a math formula which equals 24? You may use each number only once, but you can use parentheses.

     
../images/485723_1_En_1_Chapter/485723_1_En_1_Figa_HTML.jpg
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.161.222