20 câu hỏi phỏng vấn Java dành cho Junior developer – Cộng đồng Java Việt Nam | Java Việt Nam | Java SE, Java EE, Android, Spring Framework

(c+1) về kiểu kí tự là do: c là kiểu kí tự, còn 1 là kiểu số nguyên. Mà do kiểu số nguyên lớn hơn kiểu kí tự nên: : Kiểu kí tự + Kiểu số nguyên = Kiểu số nguyên. Nên mình phải ép về kiểu kí tự để xuất ra được dạng kí tự đúng vậy không ạ?

Java:

import java.util.Scanner;

public class Input {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char c = sc.next().charAt(0);
        System.out.println((char)(c + 1));
    }
}

Anh/Chị cho em hỏi là tại dòng: System.out.println((char)(c + 1)); –> Mình épvề kiểu kí tự là do:là kiểu kí tự, cònlà kiểu số nguyên. Mà do kiểu số nguyên lớn hơn kiểu kí tự nên: : Kiểu kí tự + Kiểu số nguyên = Kiểu số nguyên. Nên mình phải ép về kiểu kí tự để xuất ra được dạng kí tự đúng vậy không ạ?

Click to expand…

It’s obvious that this boy learns JAVA without having the fundamental Computer Science knowledge. EITHER the college or university where he studies is bad OR he just learns an OOPL to become an IT man. If he does have the basic CS knowledge he would know that CS does not distinguish a

bit

from a

byte

, nor

from a

char

(acter), nor from an

int

(eger). All that is the convention set by human -hence Computer Science.

CS bases on

binary system

(or digital) which has only two states ON or OFF. An ON or an OFF is called a

bit

. To represent the human written symbols (or letters/characters) we need more than one bit. For the English language it’s enough to have

8 bits

to represent all the symbols. But some Asian languages have more written symbols than just 256 symbols and that requires more bits than merely 8 bits. All advanced OOPLs use

16 bits

to represent a character. Unused parts are set to state 0 (zero or off).

But computer still works with bits and knows

only ONE arithmetic operation

(addition) and some logical operations (AND, OR, NOT, XOR, SHIFT, etc.). Other arith. operations (sub, mul, div, mod, log, etc.) are derived from Addition in conjunction with the logical operation NOT (called the complement), SHIFT. So, an addition of

on a Vietnamese forum. The man asked:It’s obvious that this boy learns JAVA without having the fundamental Computer Science knowledge. EITHER the college or university where he studies is bad OR he just learns an OOPL to become an IT man. If he does have the basic CS knowledge he would know that CS does not distinguish afrom afrom a(acter), nor from an(eger). All that is the convention set by human -hence Computer Science.CS bases on(or digital) which has only two states ON or OFF. An ON or an OFF is called a. To represent the human written symbols (or letters/characters) we need. For the English language it’s enough to haveto represent all the symbols. But some Asian languages have more written symbols than just 256 symbols and that requires more bits than merely 8 bits. All advanced OOPLs useto represent a character. Unused parts are set to state 0 (zero or off).But computer still works with bits and knows(addition) and some logical operations (AND, OR, NOT, XOR, SHIFT, etc.). Other arith. operations (sub, mul, div, mod, log, etc.) are derived from Addition in conjunction with the logical operation NOT (called the complement), SHIFT. So, an addition of

  • bytes
  • chars

will be done as if they were two integers. For example:

‘A’ +1 = 66

or Hex.

42

. It’s exactly the hex. number that represents the letter B. To convert the number 66 (or x42) to the symbol of the letter

B

a Character table is required. The mapping principle is simple: key to the symbol is the number itself. The key of letter A is x41, B is x42, etc. The mapping technique is called “Casting”. Just like molten metal which can be cast to any predefined form.

Java:

System.out.println((char)('A' + 1)); // will produce the letter 'B' using the mapping cast (char)
System.out.println(('A' + 1)); // will produce the number 66 because there is NO hint to the mapping

Good to see someone who contributes somethings to this forum. All that what you wrote is fine and very helpful. However IT developing work is not THE WORK OF A SPECIFIC OOPL (Object Oriented Programming Language), BUT A WORK OF UNDERSTANDING COMPUTER SCIENCE (CS) IN GENERAL. Java or C# or C++ or even the ancient COBOL is just a problem-solving tool. If one does not understand the matter that he/she works with then the working tool is useless -even he/she masters the tool exceptionally. Let me give you an example that I’ve found this postingwill be done as if they were two integers. For example:or Hex.