Important Concept about string Flashcards

1
Q

Even number Analysis:

A

If(8%2 = 0 ) // check if I is even
If (I % 2 == 1) // check if I is odd number
1. even numbers are numbers that are divisible by 1 and the number itself.

  1. odd number are numbers that are not divisible by two(2) evenly. they have a remainder
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Display the sum of an integer
enter by the user

A

while(true){
// condition is always true.
// so we need a break statement
// to comes out of the loop.
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

1.sum of the Strict divisor of an Integer: Example: 6 = 1+2+3=6
2. what do we means by strict divisor of a number?

A

The strict divisor of a number is n / 2.
the strict divisor of a number is an integer that evenly divides another number without leaving a remainder, except for the number itself. in order words, it is a divisor that is smaller than the number itself.
the strict divisor of 12 are : 2,3,4, and 6. 1 is a divisor of 12, but it is not a strict divisor because 1 is equal to the number itself(12).
1. i <= n/2 means
2.sum += i means that we are adding the value of i to sum.
3. if( number%i == 0) means we check if the number enter is divisible by the current number i . if the remainder is zero, it means i is a divisor of number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. what is a prime number?
  2. how to check if a number is prime or not
A
  1. prime number is a number that cannot be evenly divided by any other number except 1 and itself. example( 2,3,5,7.9).

2.using boolean logic.
boolean isprime = true;
isprime = false;
3. i<=n/2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. Sequence of integer.
A
  1. if( n< o)
    break;
    chenk if a number is a negative
  2. this code update our max and min value using a tenaray operator:
    max = n> max? n : max;
    min = n < min? n: min;
  3. this also update a max value and a min value. as the above code.
    if ( n > max)
    max = n;
    if( n < min)
    min = n;
  4. this make sure that n is not a negative number:
    if 9 n >= 0){
    // statements
    if this statement is not executed the else will be executed. if the number from the use is a negative the if statement will not be executed the else will be executed.
    }
    else
    statement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. Sum of digit of an integer.
    example: 108= 1 + 0+8 = 9
A
  1. sum += number %10 this get the last digit of the number and add it to sum.
  2. number /=10; remove the last digit. this also divide the number by number and add the result back to number
    example: number = number/10;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. The Fibonacci sequence
A

1 i < n -2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. String with space after each character
A

1.name.CharAt(i) this print the character at the current index i.
of any element or data store in the name variable. example: Darius: the first index is 0, so the first character is D this will print the character the character D in the string.
charAt(); this is a method in java that is used to get the character at a specific index of a string data.

  1. name.length()-1 means we are subtracting 1 from the length of the string to get the last character in the string
  2. name.length-1 returns the number of characters in the string.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

1.Reverse a string
2. how do you reverse a string

A
  1. string reverse= “ “; this variable is initialized to store a value. this is similar to int sum = 0; which we can add the sum of number to the variable sum.
  2. to reverse a string you have to start from the last index of the string to the first index. example: int i = number.length-1; i >=0; i–;
    a. number.length-1 get the last index of the character.
    b. i <=0 get the first element of the string.
    c. i– we decrease the value of i by one.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. Palindrome String.
  2. what is a palindrome string.
A
  1. palindrome string is a sequence of characters that reads the same forwards and backwards. Example: NOON, Level, radar
  2. str.CharAt(i) == str.charAt(j) this compare the character a index i and the character at index j.
  3. String str = “noon”;
    boolean ispolindrome = true; this means that we set the string “noon” to be true. we assume that “noon” is a polylindrome string.
  4. using the tenary operator:
    ispalindrome? “palindrome : “notpalindrome”
    if ispalindrome is true we will return palindrome if false we return notpalindrome.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly