Java

JAVA 기본 문법 eclipse콘솔에 한글 나오게 하기

leopard4 2023. 1. 17. 17:16
public class Hello {

	// 1. cpu는 main함수부터 실행된다.
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		System.out.println("hello~~~");
		System.out.println("안녕하세요~~~");
		
		// 2. 변수를 처음 사용할때는, 변수명 왼쪽에 데이터 타입을 붙여준다.(한번만)
		// 떡볶이 1인분에 2천원이다.
		
		String food = "떡볶이";
		
		int price = 2000;
		
		float rate1 = 15.3f;
		
		double rate = 15.4;
		
		food = "고등어";
		
		int total = price * 3;
		
		System.out.println(food);
		System.out.println(price);
		System.out.println(total);
		System.out.println(rate1);
		System.out.println(rate);
		
		
		double lat;
		double lng;
		
		lat = 25.1234;
		lng = 127.4443;
		
	}

}

 

public class VarTest {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		
		int a = 12;
		int b = 13;
		float c = 0f;
		
		// 정수 나누기 정수 = 결과도 정수!!
		c = (a + b) / 2.0f;
		System.out.println("a와 b의 평균은 = " + c);
		
		c = (float) (a + b) / 2;
		System.out.println("a와 b의 평균은 = " + c);
		
		a = 20 ;
		b = 10 ;
		int g = 0;
		
		g = a + b ;
		System.out.println(g);
		
		g = a-b ; 
		g = a * b ;
		g = a / b ;
		
		g = a % b ; 
		System.out.println(g);
		
		
	}

}

 

 

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		int a = 10;
		int b = 20;
		
		System.out.println( a == b );
		System.out.println( a != b );
		System.out.println( a > b );
		System.out.println( a < b );
		System.out.println( a >= b );
		System.out.println( a <= b );
		
		int c = 30 ;
		int d = 25;
		
		System.out.println( a == 10  &&  c == d );
		System.out.println( a >  10  &&  c != d );
		System.out.println( a == 10  ||  c == d );
		System.out.println( a >  10  ||  c != d );
						
		// 코멘트는 이렇게 한다.
		
		/* 여러줄 걸쳐서 하고 싶을
		 * 때에는 이거 사용해도 
		 * 된다.
		 */
		
		if (a > 10) {
			System.out.println("Hello");
		} else {
			System.out.println("Bye~");
		}
		
		int score = 60;
		// 스코어가 90점 이상이면 A
		// 70이상 90 미만 이면 B
		// 60~70이면 C
		// 나머지는 F
		
		if (score >= 90) {
			System.out.println("A");
		} else if (score >= 70 && score < 90) {
			System.out.println("B");
		} else if (score >= 60 && score < 70) {
			System.out.println("C");
		} else {
			System.out.println("F");
		}
		
		
		
		
		
		
		
	} 
	
}

 

메뉴바 run의 Configurations 에서 encoding 을 system encoding 으로 설정 apply run

 

프로젝트를 생성할때는 java로 하고 

클래스를 생성할때는 첫글자는 대문자로

메인함수를 포함하는것에 체크.