ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด/JAVA

[JAVA] getNumericValue() ๋ฉ”์†Œ๋“œ

NaNaRin๐Ÿ™ƒ 2021. 1. 6. 18:13

docs.oracle.com/en/java/javase/15/docs/api/java.base/java/lang/Character.html#getNumericValue(int)

 

Character (Java SE 15 & JDK 15)

All Implemented Interfaces: Serializable, Comparable , Constable public final class Character extends Object implements Serializable, Comparable , Constable The Character class wraps a value of the primitive type char in an object. An object of class Chara

docs.oracle.com


 

java.lang.Character.getNumericValue(char)

 

public static int getNumericValue(char ch)

 

์ˆซ์ž ํ˜•ํƒœ์˜ charํ˜•์„ intํ˜•์œผ๋กœ ๋ณ€ํ™˜

 

๋งค๊ฐœ๋ณ€์ˆ˜ char : 

๋ณ€ํ™˜ํ•˜๊ณ ์ž ํ•˜๋Š” charํ˜• ์ˆซ์ž

 

๋ฐ˜ํ™˜๊ฐ’ int :

๋ณ€ํ™˜๋œ intํ˜• ์ˆซ์ž

 

Character.getNumericValue(char)

 


์˜ˆ์ œ

public class GetNumericValueEx {

	public static void main(String[] args) {
		String s = "342";
		
		char ca = s.charAt(0);
		char cb = s.charAt(1);
		char cc = s.charAt(2);
		
		int ia = Character.getNumericValue(ca);
		int ib = Character.getNumericValue(cb);
		int ic = Character.getNumericValue(cc);
		
		System.out.println(ia + ib + ic);
	}
}

 

์ถœ๋ ฅ

9

 

 

์‚ฌ์šฉ ์˜ˆ : nanarin.tistory.com/2