예제)
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
public class Test12 {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(
new InputStreamReader(System.in));
int a,b;
System.out.print("수 ?");
a=Integer. parseInt(br.readLine());
/* 내가 했던 방법
if(a>0) {
System.out.println("절대값:"+a);
} else
System.out.println("절대값:"+-a);
*/
if(a>0)
b=a;
else
b=-a;
System.out.println("절대값:"+b);
System.out.println("종료 !!!");
}
}
결과) 수를 입력받아 절대값으로 출력
수 ?-5
절대값:5
종료 !!!
'자바 > 문법' 카테고리의 다른 글
if ~ else 문(평년, 윤년) (0) | 2013.05.09 |
---|---|
if 연속문(세가지 숫자를 입력 받아 작은수부터 출력) (0) | 2013.05.09 |
if ~ else if문(큰수 작은수 판별) (0) | 2013.05.09 |
if ~else if 문(수우미양가) (0) | 2013.05.09 |
if문과 if~else, if~else if~else문 (0) | 2013.05.09 |