기본적인 사칙연산법은 C언어와 크게 다르지않아 패스를 하겠습니다.
사실 제어문도 그닥 다르진 않지만 한번 사용법 정도만 적어두겠습니다.
if-else문
import java.util.Scanner;
public class Larger{
public static void main(String[] args){
int x,y,max;
Scanner input=new Scanner(System.in);
System.out.print("첫번째 정수");
x=input.nextInt();
System.out.print("두번째 정수");
y=input.nextInt();
if(x>y)
max=x;
else
max=y;
System.out.print("큰수는?"+max);
}
}
new Scanner는 scanf 와 같을겁니다. 또한 new 할당이라 메모리를 미리 할당 받는 방식인것 같습니다.
말그대로 input.nextInt()는 변수에 값을 int를 넣어주는 메소드 인것같습니다.
import java.util.Scanner; 스캐너 라이브러리입니다.
switch문
크게 c랑 문법상 다르지않습니다.
Switch(number)
{
case 0:
System.out.println("없음");
break;
case 1:
System.out.println("하나");
break;
case 2:
System.out.println("둘");
break;
case 3:
System.out.println("삼");
break;
default:
System.out.println("기본");
break;
}
for문 /while 문
반복문도 마찬가지로 c언어와 큰차이가 없습니다.
public class Loop{
public static void main(String[] args){
int whileValue,forValue;
whileValue=0;
forValue=0;
while(whileValue<9){
whileValue++;
}
System.out.println("whileValue"+whileValue);
for(int i=0;i<10;i++){
forValue++;
}
System.out.println("forValue"+forValue);
}
}
'프로그래밍언어 > JAVA' 카테고리의 다른 글
JAVA<Class,Object,Method-01> (0) | 2019.11.20 |
---|---|
JAVA <Array-List/래그드 array> (0) | 2019.11.17 |
Java<배열 Array> (0) | 2019.11.14 |
JAVA 기초 개념 (0) | 2019.11.13 |
자바 들어가기전에.. (0) | 2019.11.13 |