Java 1차원 배열, 1D array 배우기


public class Application{

     public static void main(String[] args){
       String[] numbers = new String[4];   //declaration important

   numbers[0] = "Welcome";

   numbers[1] = "To";

   numbers[2] = "My";

   numbers[3] = "Channel";
   for(int i = 0; i < 4 ; i++){

System.out.println(numbers[i]);

   }

   

   int[] Hi = new int[4];

   Hi[0] = 1

   Hi[1] = 2

   Hi[2] = 22

   Hi[3] = 44

   for(int j = 0 ; j < 4 ; j++){

       System.out.println(Hi[j]);

   }

}

}


[result]

Welcome

To

My

Channel

1

2

22

44

[Java]  Operator tutorials 연산 공부 정리


Data Types are int, boolean, and char.

Variables are used to store values.

Whitespace helps make code easy to read for you and others.

Comments describe code and its purpose.


Arithmetic Operators include +, -, *, /, and %.

Relational Operators include <, <=, >, and >=.

Equality Operators include == and !=.


A full understanding of these concepts is key to understanding the remainder of the Java course. Let's keep going!

[Java] Equality Operator 동등연산자 공부하기 !


Equality Operators

You may have noticed that the relational operators did not include an operator for testing "equals to". In Java, equality operators are used to test equality.


동등연산자

아마 " ~와 같다" 라는 말을 들어보신 적이 있습니다. 예를 들어, "a는 b와 같다."를 수학식으로 표현하게 되면 "a=b" 입니다.

하지만 프로그래밍 언어에서는 int a = 0;  "정수형 데이터타입 a는 0과 같다." 라고 하기도 하지만 어떻게 보면 틀린 표현입니다.

왜냐하면 정수형 a 변수는 말그대로 변수라서 항상 0와 같을 수 없습니다. 그리고 다음 라인에서 a = 3; 을 작성하면 3이라는 값이 a에 저장되는 것입니다.

그래서 두 값이 동등한지 비교할 수 있는 연산자가 동등연산자입니다.


The equality operators are:


==: equal to. 같다.

!=: not equal to. 같지 않다.


Equality operators do not require that operands share the same ordering. For example, you can test equality across boolean, char, or int data types. The example below combines assigning variables and using an equality operator:


동등연산자는 항상 숫자일 필요가 없습니다. 캐릭터 타입, 불린 타입, 실수형 (double), 정수형(integer) 타입 어떤 것들도 비교할 수 있습니다.


EX]

char Char1 = 'a';

int Int1 = -3;

System.out.println(Char1 == Int1);


The example above will print out false because the value of Char1 ('a') is not the same value as Int1 ('-3').

위 예제는 false 거짓 결과값을 반환할 것입니다. 왜냐하면 Char1 ('a')가 가진 값과 Int1 ('3')이 가진 값이 다르기 때문입니다.


대신에

System.out.println(Char1 != Int1);


라고 했다면 서로 다른 값들을 가진 것이 사실이기 때문에 true를 반환할 것입니다.




[Java] Relational Operators 비교 연산자 공부하기 !


비교 연산자 (Relational Operators) 라고 하면 어떤 것들이 떠오르나요?

일단 비교 연산자라고 하니 두 개이상의 대상을 비교해야 하는/ 할 수 있는 연산자라고 생각이 듭니다.

기본적으로 비교연산자는 항상 Boolean value를 return 합니다. 

즉, 혹은 거짓만 비교 연산자의 결과값이 될 수 있습니다.


Here are a few relational operators:

아래 비교 연산자들의 예시들을 몇개 보겠습니다.


< : less than. 작다

<=: less than or equal to. 작거나 같다.

>: greater than. 크다.

>=: greater than or equal to. 크거나 같다.


A relational operator is placed between the two operands (the terms that you want to compare using the relational operator). The result of a relational operation is printed out in the following statement:


비교 연산자는 두 숫자 사이에 위치하게 되며, 항상 왼쪽을 기준으로 설명합니다.


예를 들어,

System.out.println(5 < 7); 와 같은 코드를 작성했다면, 5가 7 보다 크다는 논리식이 옳기 때문에 true라는 결과값을 반환할 것입니다.


relational operator는 항상 boolean value만 반환합니다. 기억하세요 !





[Java] Modular Arithmetic 모듈러 연산, 나머지 연산자 공부하기 !


Math: % ( modulo )


The modulo operator - represented in Java by the % symbol - returns the remainder of dividing two numbers.

For example, 15 % 6 will return the value of 3, because that is the remainder left over after dividing 15 by 6.


자바에서 '나머지 구하기 연산자 ( 모듈러 )'는 "%"로 나타냅니다. 두수의 나머지를 계산할 때 사용되는 연산자입니다.
예를 들어, 15 % 7 = 1 입니다. 2 * 7 = 14 + 1 = 15 이기 때문이지요.
또 다른 예를 들어보겠습니다. 51 % 17 = ??? 한번 생각해보세요. 연산결과로 0을 예상하셨다면 정답입니다.

EX]
public class Modular_Arithmetic{
public static void main(String[] args){
int a = 3;
if (!( 15 % a )){
System.out.println("3의 배수입니다!, Multiple of three !");
}
}
}

아주 간단한 예시를 들어봤는데요. 지금은 모르셔도 되는 conditional statement 조건제어문 If 입니다.
다음부터 계속해서 배워보도록 하겠습니다.


+ Recent posts