[6] 데이터와 연산

서희찬·2022년 1월 16일
0

JAVA - 생활코딩 

목록 보기
3/12
post-thumbnail

다양한 데이터


자바에 있는 데이터에 대해 알아보자 !

public class dataType{
	public static void main(String[] args) {
		System.out.println(6); //Number  
		System.out.println("Six");  // String
		System.out.println("6"); // String
		
		System.out.println(6+6); //12 
		System.out.println("6"+"6"); // 66, 문자열은 곱하기 불가 
		System.out.println("1111".length()); // 4 문자열 길이 반환
		//System.out.println(111.length() ); //숫자는 length 불가 
		
		
	}
}

문자열과 숫자..! 를 출력하는 것을 배워땅

파일을 만들때 매번 만들필요 없이 new->class로 만들어도 된다.

숫자와 연산

package data_and_type;

public class Number {

	public static void main(String[] args) {
		// Operator : 연산자 
		System.out.println(6+2); // 8 
		System.out.println(6 - 2); // 4 
		System.out.println(6*2); // 12
		System.out.println(6/2); // 3
		
		System.out.println(Math.PI); //3.141592653589793
		System.out.println(Math.floor(Math.PI)); // 3.0
		System.out.println(Math.ceil(Math.PI)); // 4.0 
	}

}

Math로 간편하게 숫자의 연산을 다룰 수 있다.

문자열의 표현

package data_and_type;

public class StringApp {

	public static void main(String[] args) {
		System.out.println("Hello world"); // String 
//		System.out.println('hdsad'); //Error '' -> character 
		
		System.out.println("Hello" + "World");  
		
		// new Line 
		System.out.println("Hello \n World");
		
		//escape 
		// Hello "WORLD" -> \" 으로 ..  
		System.out.println("Hello \"World\" ");

	}

}

뭐.. 작은 따옴표는 문자이고 큰 따옴표는 문자열로 구분한다
그리고 나머지는 뭐 다른언어랑 같다

문자열 다루기

package data_and_type;

public class StringOperation {
	public static void main(String[] args) {
		
		System.out.println("Hello World".length()); 
		System.out.println("Hello, [[name]].. bye.. ".replace("[[name]]","egoing")); //replace 
	}
}
profile
부족한 실력을 엉덩이 힘으로 채워나가는 개발자 서희찬입니다 :)

0개의 댓글