package ex01.Printf;

public class MainEntry___ {
	public static void main(String[] args) {
		
		System.out.printf("\n\n\n%10.1f\n", 12.34); 
		System.out.printf("%3.1f\n", 12345.34789);
		System.out.printf("%.2f\n", 12345.34789);
		System.out.printf("메시지 출력 : %.10f\n", 12345.34789); //**
		System.out.printf("메시지 출력2 : %.15f\n", 12345.3478987654); //**	
	}
}

//제어문자 : \문자 - \n, \t, \a,.....
//printf() - 서식에 맞춰서 출력 : %문자 - %c, %s, %d, %i, %f,...

 

      12.3
12345.3
12345.35
메시지 출력 : 12345.3478900000 ->%.10f는 소수점 10자리까지 출력하라는 뜻 
메시지 출력2 : 12345.347898765400000 ->%.15f는 소수점 15자리까지 출력하라는 뜻

'JAVA > 02_기본 구문' 카테고리의 다른 글

클래스 변수 / 지역 변수  (0) 2021.01.11
Identifier Definition Rule / 변수  (0) 2021.01.10
printf  (0) 2021.01.10
print / println / printf  (0) 2021.01.10
Hello Java!  (0) 2021.01.10
package ex03.operator;

public class OperatorTest {
	static int Num; //클래스변수 = static변수 
	static double dd;
	static String str;
	
	public static void main(String[] args) {
		System.out.println(Num); //static변수는 정수: 0, 실수:0.0, 문자열:null로 초기화됨
		System.out.println(dd + "\t," + str); //static변수는 초기화하지 않아도 default값이 있음 
		System.out.println("---------------------------");
		
		int x=10, y=20; //자바에서 지역변수는 처음부터 값을넣어서 초기화 해야 한다 
		int gob=x*y;
		System.out.println(gob);
	}

}

->클래스 변수 = static변수 : static변수는 초기화하지 않아도 default값이 있음 

->지역 변수 : 자바에서 지역변수는 처음부터 값을넣어서 초기화 해야 한다

'JAVA > 02_기본 구문' 카테고리의 다른 글

%.10f 와 %.15f  (0) 2021.01.11
Identifier Definition Rule / 변수  (0) 2021.01.10
printf  (0) 2021.01.10
print / println / printf  (0) 2021.01.10
Hello Java!  (0) 2021.01.10
  • 변수명에 공백은 불가능
  • 변수명에 예약어(ex:class)는 불가능

 

  • '문자'-> 1byte, char
  • "문자열"-> 2byte, 항상 뒤에 null문자 포함, string 

      =>모든 부분에서 대소문자 구분!

 


package ex01.Printf;

public class MainEntry___ {
	public static void main(String[] args) {
		
		int a = 99;
		System.out.printf("a = %d\n", a);
		a = 55;
		System.out.println("a = " + a);
		
		//int class = 99;
		
		int A = 90;
		char ch = 'k';
		float f = 12.34f;
		
		System.out.println("A = " +A);
		
		boolean flag = true;
		System.out.println(flag);
		//flag = 1;

		
	}
}

->변수는 메모리상에 공간이 잡혀야만 사용가능

 

'JAVA > 02_기본 구문' 카테고리의 다른 글

%.10f 와 %.15f  (0) 2021.01.11
클래스 변수 / 지역 변수  (0) 2021.01.11
printf  (0) 2021.01.10
print / println / printf  (0) 2021.01.10
Hello Java!  (0) 2021.01.10
package ex01.Printf;

public class MainEntry {
	public static void main(String[] args) {
		System.out.println("yyr");
		System.out.printf("%c %s %d %f", 'A', "yerin", 3000, 12.34); //%f: 소수점 default로 6자리 출력
		System.out.println();
		System.out.printf("%c %s %d %10.1f \n", 'A', "yerin", 3000, 12.34); //%M.Nf
		System.out.printf("\n\n%10.1f\n", 12.34);
		//%10.1f는 공간을 10자리수로 만들고 그 안에서 해당 수를 넣어 소수점 1자리까지 나타냄
		
		
		System.out.printf("%3.1f\n", 12345.3456789); //소수점위의 정수들은 정해진 공간크기와 상관없이 모두 출력됨 
		System.out.printf("%.2f", 12345.3456789); 
		
	}
}

//제어문자: \문자  -\n, \t, \a....
//printf() - 서식에 맞춰서 출력: %문자 - %c, %s, %d, %i, %f,...

yyr
A yerin 3000 12.340000 ->%f: 소수점 default로 6자리 출력
A yerin 3000       12.3 ->%10.1f는 공간을 10자리수로 만들고 그 안에서 해당 수를 넣어 소수점 1자리까지 나타냄


      12.3 ->%10.1f는 12.34를 10칸의 공간에서 소수점 첫째자리 수까지 나타냄
12345.3 ->소수점위의 정수들은 정해진 공간크기와 상관없이 모두 출력됨 
12345.35

 

->제어문자: \문자  -\n, \t, \a....
->printf() - 서식에 맞춰서 출력: %문자 - %c, %s, %d, %i, %f,...

'JAVA > 02_기본 구문' 카테고리의 다른 글

%.10f 와 %.15f  (0) 2021.01.11
클래스 변수 / 지역 변수  (0) 2021.01.11
Identifier Definition Rule / 변수  (0) 2021.01.10
print / println / printf  (0) 2021.01.10
Hello Java!  (0) 2021.01.10
package ex02.datatype;

public class Infomation {
	public static void main(String[] args) {
		
	// 이름/주소/연락처 - print / println / printf
	System.out.print("이름: yr");
	System.out.println("주소: 서울시");
	System.out.printf("번호: 010-1111-2222");
	
	System.out.println(); //줄바꿈 효과
	
	System.out.println(300 + 3); //정수형 -> 연산
	System.out.println("300 " + 3); //문자형 -> 문자형 결합(띄어쓰기도 나타남) 
	

	}
}

이름: yr주소: 서울시
번호: 010-1111-2222
303 -> 정수형은 "+"하면 연산이 됨
300 3 -> 문자형은 "+"면 문자형 결합이 됨(띄어쓰기도 표현o)


 print()  - 개행없이 출력 
 printf() - 서식에 맞춰서 출력 : %문자 - %c, %s, %d, %i, %f,...
 println() - 출력 및 개행 

'JAVA > 02_기본 구문' 카테고리의 다른 글

%.10f 와 %.15f  (0) 2021.01.11
클래스 변수 / 지역 변수  (0) 2021.01.11
Identifier Definition Rule / 변수  (0) 2021.01.10
printf  (0) 2021.01.10
Hello Java!  (0) 2021.01.10
package ex01.basic;

public class Hello {  //클래스 
	
	public static void main(String[] args) { //시작점(진입점)
		System.out.println("Hello Java! eclipse");
		
	} //end main 
	
} //end class 

'JAVA > 02_기본 구문' 카테고리의 다른 글

%.10f 와 %.15f  (0) 2021.01.11
클래스 변수 / 지역 변수  (0) 2021.01.11
Identifier Definition Rule / 변수  (0) 2021.01.10
printf  (0) 2021.01.10
print / println / printf  (0) 2021.01.10

+ Recent posts