|   FORUM      |     Tutoriales    |     KIO4 |      
   Start B4A (Basic4Android) App inventor 2 Arduino
   Elastix - VoIP Things of Windows Interesting Webs  Telecomunications

 


Nuevo concurso para España, Argentina, Brasil, Chile, Colombia, Ecuador, México, Perú y Portugal.

App Inventor 2
Programming mobi
le phones with Android 
by App Inventor 2 - Juan Antonio Villalpando

- Initiation Tutorial App Inventor 2 -

Return to tutorial index

____________________________

49.- Odd / Even. Multiple of 4. Divisors of a number.

ip49_even_odd

- Presentation.

- Even - Odd.

- We write a number and app answer whether it is even or odd.

- We use the operator module, it makes a division between two numbers, but what we get rest division.

- If to divide a number by 2, the remainder is zero, that is even, otherwise it is ODD.

_________________
Design

- We put letters in Bold. The size: Fill to parent.
- The TextBox in "NumberOnly". FontSize: 30. Bold.
- The Button with Width and Height 60 pixel container.

_________________
Blocks

Extension.

We can make a similar code where indicated if a year is a leap year or not.

The code would be similar to what we have seen, only in the modulo operator rather than put 2 put to 4.

If by dividing one year from 4 the remainder is zero, it means that this year is a leap year, otherwise it is not.

Remember that leap years are Olympic years.

Module: two numbers is divided and the remainder is taken. The remainder has the same sign as the denominator.
Remaining:
two numbers is divided and the remainder is taken.
The remainder has the same sign as the numerator.
Quotient:
get the integer quotient without decimals.


______________________________

49B.- Divisors of a number.

ip49b_divisors

- Write a number and should give us the divisors of that number, separated by a hyphen.

_________________
Design

_________________
Blocks

- Introduce a number.
- When you press the button passes the TextBox to the variable number.
- Enter a loop that is performing an operation as many times as the number entered.

- In each execution of the loop, performs the module number from the current value of n.
- If the modulus (remainder of the division) is zero, the number n is divisible, in this case added to the text variable: dividers.
- At the end all the information of the dividers variable is set in the Label2.

- Note that the Variable dividers do this:

divisors = divisors join - join n

That is, the variable text divisors, is adding the new values ​​of divisors.

Loop

n loop starts from 1.
The code is done run that is inside.
When you just start again, but this time the value n is incremented by 1 and now is 2.
It
is carried out again to execute code the value of n reaches to the end number

 

- My e-mail:
juana1991@yahoo.com
- Who I am. - Cookies. Texts and images propierty autor:
© Juan A. Villalpando
Not copy texts neither images.
We use our own cookies and third-party cookies on our websites to maintain the session and your preferences, customize your user experience and obtain website use statistics.
Si continúa navegando consideramos que acepta su uso. OK    Más información