검색결과 리스트
java에 해당되는 글 7건
- 2020.02.11 JAVA 백준 1912 연속합
- 2020.02.06 JAVA 백준 1463번 1로 만들기
- 2020.02.06 JAVA 백준 1000번 A+B
- 2013.10.31 [설정] java build path
- 2013.06.12 [JAVA] OOP 다형성 - 오버로딩
- 2013.06.12 [JAVA] OOP Encapsulation 캡슐화
- 2013.06.11 [JAVA] 자바기본1: 연산자, 형변환, 문자열 출력, if문, 윤년출력
글

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
long dp[][] = new long[N][2];
st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
dp[i][0] =Integer.parseInt(st.nextToken());
}
long max = -1;
if(dp[0][0]> 0) {
dp[0][1] = dp[0][0];
}
max = dp[0][0];
for (int i = 1; i < N; i++) {
dp[i][1] = dp[i-1][1]+dp[i][0] > dp[i][0] ? dp[i-1][1]+dp[i][0] :dp[i][0];
max = dp[i][1] > max ? dp[i][1] : max ;
}
System.out.println(max);
}
}
'알고리즘' 카테고리의 다른 글
| JAVA 백준 1463번 1로 만들기 (0) | 2020.02.06 |
|---|---|
| JAVA 백준 1000번 A+B (0) | 2020.02.06 |
설정
트랙백
댓글
글

DP로 풀었다.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
long dp[] = new long[N+1];
dp[0] = Long.parseLong("0");
dp[1] = Long.parseLong("0");
for(int i=2; i<=N; i++) {
// System.out.println("N=="+N+",i=="+i);
if (i%3 == 0) {
// System.out.println(i+"::mod3");
if (dp[i]==0 || (dp[i] >1+dp[i/3])) {
dp[i] = 1+dp[i/3];
}
}
if (i%2 == 0) {
// System.out.println(i+"::mod2");
if (dp[i]==0 || (dp[i] >1+dp[i/2])) {
// System.out.println(i/2+">"+dp[i/2]);
dp[i] = 1+dp[i/2];
}
}
if((i%3 != 0 && i%2 != 0) || dp[i] > dp[i-1]+1) {
// System.out.println(i+"::1+"+dp[i-1]);
dp[i] = dp[i-1]+1;
}
// System.out.println(i+"="+dp[i]);
}
System.out.println(dp[N]);
}
}
'알고리즘' 카테고리의 다른 글
| JAVA 백준 1912 연속합 (0) | 2020.02.11 |
|---|---|
| JAVA 백준 1000번 A+B (0) | 2020.02.06 |
설정
트랙백
댓글
글

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
System.out.println(a+b);
}
}
'알고리즘' 카테고리의 다른 글
| JAVA 백준 1912 연속합 (0) | 2020.02.11 |
|---|---|
| JAVA 백준 1463번 1로 만들기 (0) | 2020.02.06 |
설정
트랙백
댓글
글
마우스 우클릭 - Priperites - Java bulid Path - Libraries -> Workspace default JRE (jre6)
=> 소스 가져와서 실행했더니 JDK 버전 떄문에 난 오류.
Bulid Path 만 잡아주면 된다.
오랜만에 안드로이드 만지려니 헷갈리네 ㅜㅜ
'ANDROID' 카테고리의 다른 글
| [설정] already exists but is not a source folder. Convert to a source folder or rename it. (0) | 2013.10.31 |
|---|
설정
트랙백
댓글
글
/*
오버로딩(다중정의)
1. 자바 다형성구현기법 중의하나이다.
2. 정의: 같은메쏘드 이름으로 여러개를 정의하는방법
- 규칙:
* 메쏘드의 이름이 같아야한다.
* 메쏘드의 인자의 숫자가 다르거나
* 메쏘드의 인자의 타입이 달라야한다.
* 메쏘드의 리턴타입,접근지정자는 상관없다.
*/
//------ Printer.java ------
public class Printer {
public void print (int a){
System.out.println("int print: "+a);
}
public void print (char c){
System.out.println("char print: "+c);
}
public void print (String str){
System.out.println("String print: "+str);
}
public void print (boolean b){
System.out.println("boolean print: "+b);
}
public void booleanprint (boolean b){
System.out.println("boolean print2: "+b);
}
public static void main(String[] args) {
Printer p = new Printer();
p.print(false);
p.booleanprint(true); //얘는 오버로딩 안하고 그냥 쓰는거.
p.print("U");
p.print(7);
p.print("HAVE A GOOD TIME");
}
}
//------ Overloading.java ------
public class Overloading {
public void method (){
System.out.println("public void method ()");
}
public void method (int a){
System.out.println("public void method (int a)= "+a);
}
//인자의 타입
public void method (float a){
System.out.println("public void method (float a)= "+a);
}
public void method (char a){
System.out.println("public void method (char a)= "+a);
}
//인자의 수
public void method (int a, int b){
System.out.println("public void method (int a, int b)= "+a+", "+b);
}
/*
//메소드 리턴타입
public void method1 (){
}
public int method1 (){
return 0;
}
//접근 지정자
public void method2 (){
}
private void method2 (){
}
*/
public static void main(String[] args) {
Overloading ol = new Overloading();
ol.method() ;
ol.method(3.1f);
ol.method(3);
ol.method('K');
ol.method(1, 2);
}
}
'JAVA > 자바실습' 카테고리의 다른 글
| [JAVA] OOP Encapsulation 캡슐화 (0) | 2013.06.12 |
|---|---|
| [JAVA] OOP BASIC (객체지향 프로그래밍 기초) (0) | 2013.06.12 |
| [JAVA] 자바기본2: For, While 문을 이용한 구구단, 별 찍기, 알파벳 출력 등 (0) | 2013.06.12 |
| [JAVA] 자바기본1: 연산자, 형변환, 문자열 출력, if문, 윤년출력 (0) | 2013.06.11 |
설정
트랙백
댓글
글
/* OOP 의 원칙
* 1. 캡슐화
* 2. 상속성
* 3. 다형성(오버로딩,오바라이딩,객체형변환)
*/
/*
* 1. 캡슐화
* - 외부클래스나 객체에서 멤버변수에 접근을 막고
* 멤버 메쏘드에만 접근할수있도록 클래스를 설계하는방법
* - 구현 : 멤버변수의 접근제한자를 private
* 멤버메소드의 접근제한자는 public 으로한다.
* public ==> 어떤 외부클래스에서든지 접근가능
* private==> 어떤 외부클래스에서든지 접근불가능
*/
Account
/*
* - 은행의 계좌 객체를 추상화한 클래스이다.
* - 은행계좌의 데이터를 가지고 있는 클래스이다.
*
*/
public class Account {
private String no; //계좌번호
private String owner; //계좌주
private int balance; //잔액
private float iyul; //이율
/*
* 입금하다
*/
/**
*
* @param money 입금금액
*/
public void ipGum (int money){
this.balance = this.balance + money;
System.out.println(" << 입 금 완 료 >> ");
System.out.println("입 금 금 액: " + money);
this.print();
}
/*
* 출금하다
*/
/**
*
* @param money 출금금액
* @return 출금가능 여부
*/
public boolean chulGum(int money){
boolean isSuccess = false;
if (this.balance < money){
isSuccess = false;
}
else {
this.balance = this.balance - money;
isSuccess = true;
}
return isSuccess;
}
/*
* 계좌정보를 출력하다.
*/
/**
* 계좌 정보를 인출한다.
*/
public void print (){
System.out.println("==========================");
System.out.println("계 좌 번 호: "+ this.no +"\n"
+ "계 좌 주 명: " + this.owner +"\n"
+ "계 좌 잔 액: "+ this.balance +"\n"
+ "계 좌 이 율: "+ this.iyul);
System.out.println("==========================");
}
public String getNo() {
return no;
}
public String getOwner() {
return owner;
}
public int getBalance() {
return balance;
}
public float getIyul() {
return iyul;
}
public void setNo(String no) {
this.no = no;
}
public void setOwner(String owner) {
this.owner = owner;
}
public void setBalance(int balance) {
this.balance = balance;
}
public void setIyul(float iyul) {
this.iyul = iyul;
}
}
AccountMain
public class AccountMain {
public static void main(String[] args) {
Account acc1 = new Account();
/*
acc1.no ="111";
acc1.owner ="김경수";
acc1.balance =5000;
*/
acc1.setNo("111");
acc1.setOwner("김경수");
acc1.setBalance(5000);
acc1.setIyul(4.5f);
//입금
// acc1.balance = acc1.balance + 3000;
acc1.ipGum(3000);
//출금
boolean isSuccess = acc1.chulGum(56000);
if (isSuccess == true){
System.out.println(" << 출 금 완 료 >>"
+"\n 잔액: "+acc1.getBalance());
}
else {
System.out.println(" << 잔 액 부 족 >>"
+"\n 잔액: "+acc1.getBalance());
}
isSuccess = acc1.chulGum(4000);
if (isSuccess == true){
System.out.println(" << 출 금 완 료 >>"
+"\n 잔액: "+acc1.getBalance());
}
else {
System.out.println(" << 잔 액 부 족 >>"
+"\n 잔액: "+acc1.getBalance());
}
//출력
acc1.print();
}//end main
}//end class
'JAVA > 자바실습' 카테고리의 다른 글
| [JAVA] OOP 다형성 - 오버로딩 (0) | 2013.06.12 |
|---|---|
| [JAVA] OOP BASIC (객체지향 프로그래밍 기초) (0) | 2013.06.12 |
| [JAVA] 자바기본2: For, While 문을 이용한 구구단, 별 찍기, 알파벳 출력 등 (0) | 2013.06.12 |
| [JAVA] 자바기본1: 연산자, 형변환, 문자열 출력, if문, 윤년출력 (0) | 2013.06.11 |
설정
트랙백
댓글
글
/*
산술연산자
- 형태: +,-,*,/,%
*/
public class ArithmaticOperator {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a = 1, b = 2;
int result = a + b;
float result1;
System.out.println("a+b = " +result );
result = a - b;
System.out.println("a-b = " +result );
result = a * b;
System.out.println("a*b = " +result );
result1 = (float)a/b;
System.out.println("a/b = " +result1 );
result = a % b;
System.out.println("a%b = " +result );
result = 452%52;
System.out.println("452%52 = "+result);
}
}
//------ CH01. BitOrerator - 비트 연산자 ------ /*
비트연산자
-형태: | , & ,~,>>,<<
* ~ : not (모든 비트 반전)
Bit or 연산( | ) -->양쪽비트가 모두 0인경우에만 0을반환
Bit and 연산 ( & ) -->양쪽비트가 모두 1인경우에만 1을반환
*||, &&와 다른 점: |, &는 양쪽이 논리형(t,f)이면 논리형 연산을 함
*정수형이면 정수형 연산을 함.
Shift 연산자 >>,<< --> bit를 좌우측으로 이동
*/
public class BitOrerator {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int i1 = 3;
int i2 = 5;
int i3 = 7;
int result = i1 | i2;
System.out.println("3|5 = "+result);
/*
* 3 = 0000 0000 0000 0000 0000 0000 0000 0011 (4byte = 8bit)
* 5 = 0000 0000 0000 0000 0000 0000 0000 0101
* 3|5 = 0000 0000 0000 0000 0000 0000 0000 0111 = 7
* 3&5 = 0000 0000 0000 0000 0000 0000 0000 0001 = 1
*/
result = ~i1;
System.out.println("~3 = "+result);
/*
* 2의 보수 역과정
* 3 = 0000 0000 0000 0000 0000 0000 0000 0011
* ~3 = -4
* *읽는 방법: 모든 비트를 뒤집음 -> 값 +1 (보수를 취한 후 +1)
* 1111 1111 1111 1111 1111 1111 1111 1100 ->뒤집음
* 값 +1
* 1111 1111 1111 1111 1111 1111 1111 1101
* 다시 역과정을 거치면
* 0000 0000 0000 0000 0000 0000 0000 0010 -> 4인데
* 아까 뒤집을 때 맨 앞이 1이니까 -4가 답이 된다.
* */
int i = 1;
result = i<<5;
System.out.println("1<<1"+result);
boolean bresult = true | false;
System.out.println("true|false = "+bresult);
}
}
//------ CH01. CastingExam - 형 변환 예제 ------ /*
형변환(Casting)--> 숫자형데이타간에만 가능
- 형식 : (데이타타입)변수or상수;
- 자동형변환(작은데이타-->큰데이타 기억장소)upcasting
byte-->short-->int-->long-->float-->double
묵시적 형 변환
- 강제형변환(큰데이타-->작은데이타)downcasting
double-->float-->long-->int-->short-->byte
명시적 형 변환
*/
//upcasting(promotion)
public class CastingExam {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//암시적 형 변환
byte bt = 10; //내부적으로 형 변환이 일어남 int -> byte
short st = bt;
float ft =st;
//명시적 형 변환
int i =29;
short s = (short)i;
double d = 32.1241213;
int i1 = (int)d;
System.out.println(i);
System.out.println("(int)"+d+" = "+i1);
//연산시의 형 변환
//(가장 큰 항의 데이터 타입으로 모든 항이 UpCasting된 후 연산)
byte bb = 34;
short ss = 23;
int ii = 143;
long ll = 12423435234L;
float ff = 23.45f;
double dd = 234.23423211;
double result = bb+ss+ii+ll+ff+dd;
/***예외 : byte와 short의 연산은 무조건 int로 UpCasting 후에 진행***/
byte bbb =89;
short sss = 90;
int sResult = bbb+sss;
}
}
//------ CH01. HelloWorld - 문자열 출력 ------ public class HelloWorld {
public static void main (String[] args){
//문자열 출력 명령문 (주석)
System.out.println("Hello java");
System.out.println("안녕자바!");
}
}
//------ CH01. IfNested - 중첩 if문 ------ import java.util.Scanner;
/*중첩 if문
*
*
*/
public class IfNested {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int kor , eng, math;
char hakjum = ' ';
Scanner sc = new Scanner(System.in);
System.out.println("Enter Your KOR Score");
kor = sc.nextInt();
if (kor>=0 && kor<=100){
if (kor > 90){
hakjum ='A';
}else if (kor >80){
hakjum ='B';
}else if (kor > 70){
hakjum ='C';
}else if (kor > 60){
hakjum ='D';
}else {
hakjum ='F';
}
System.out.println("Your MATH Grade is "+hakjum);
}
else{
System.out.println("ERROR, SCORE is Between 0 to 100");
}
System.out.println("\nEnter Your MATH Score");
math = sc.nextInt();
if (math<0 || math>100){
System.out.println("ERROR, SCORE is Between 0 to 100");
return; //해당 경우에 하위 문장을 실행하지 않고 return
}
if (math >=90){
hakjum = 'A';
}else if (math >=80){
hakjum = 'B';
}else if (math >=70){
hakjum = 'C';
}else if (math >=60){
hakjum ='D';
}else {
hakjum ='F';
}
System.out.println("Your MATH Grade is "+hakjum);
} //end main
}//end class
//------ CH01. IfOddEven - if문 홀짝 ------ import java.util.Scanner;
public class IfOddEven {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int su ;
Scanner sc = new Scanner(System.in);
System.out.println("숫자를 입력 해주세요.");
su = sc.nextInt();
String msg ="";
if ( su % 2 ==0){
msg = "짝수";
}
else{
msg = "홀수";
}
System.out.println(su+"은( "+msg+" 입니다");
}
}
//------ CH01. IfScoreTest- if문을 이용한 성적 출력 ------ /*
//Casting을 사용하는 것이 관건!
* 값이 어떻게 잘리는지 알자 :)
*
국어,영어,수학 점수를 가지고
총점,평균,평점(A,B,C....)을 출력하시요....
- 100점이 넘는 수나 음수가 입력되면 메세지를 출력하세요
- 평균은 소수점이하 2자리수까지만 출력하세요
- 출력포맷
************************
국어: 78
영어: 56
수학: 77
총점:256
평균:78.56
평점: C
************************
*/
import java.util.Scanner;
public class IfScoreTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int kor,eng,math;
kor=71;
eng=52;
math=91;
System.out.println("국어,영어,수학 점수 입력");
kor = sc.nextInt();
eng = sc.nextInt();
math = sc.nextInt();
int total = kor+eng+math;
float everage = (float)total/3;
char hakjum;
everage = everage*100;
int trans = (int)everage;
everage = (float)trans/100;
/**점수 타당성 검사 **/
if (kor<0 || kor>100){
System.out.println("ERROR, SCORE is Between 0 to 100");
return; //해당 경우에 하위 문장을 실행하지 않고 return
}
if (eng<0 || eng>100){
System.out.println("ERROR, SCORE is Between 0 to 100");
return; //해당 경우에 하위 문장을 실행하지 않고 return
}
if (math<0 || math>100){
System.out.println("ERROR, SCORE is Between 0 to 100");
return; //해당 경우에 하위 문장을 실행하지 않고 return
}
System.out.println("************************");
System.out.println("국어: "+kor);
System.out.println("영어: "+eng);
System.out.println("수어: "+math);
System.out.println("총점: "+total);
System.out.println("평균: "+everage);
if (everage >=90){
hakjum = 'A';
}else if (everage >=80){
hakjum = 'B';
}else if (everage >=70){
hakjum = 'C';
}else if (everage >=60){
hakjum ='D';
}else {
hakjum ='F';
}
System.out.println("평점: "+hakjum);
System.out.println("************************");
}
}
//------ CH01. IfTest- if문을 이용한 True, False ------ /*
제어문
1. if 문
-형식 :
stmt0;
if(조건문 ){
//조건문 --> 논리형데이타가 반환되는 연산
// 혹은 논리형상수
stmt1;
}else{
stmt2;
}
stmt3;
조건데이타가 true인경우 stmt0-->stmt1-->stmt3;
조건데이타가 false인경우 stmt0-->stmt2-->stmt3;
*/
public class IfTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int x= 20, y= 30;
System.out.println("stmt1");
if (x > y){
System.out.println(x+" > "+y);
}
else {
System.out.println(x+" <= "+y);
}
System.out.println("stmt2");
if (x > y){
System.out.println(x+" > "+y);
}
System.out.println("stmt3");
if (x == y)
System.out.println(x+" == "+y);
System.out.println("stmt4");
if (x!=y)
System.out.println(x+" != "+y);
else
System.out.println(x+"=="+y);
}//end main
}//end class
//------ CH01. LogicalOperator - 논리 연산자 ------ import java.util.Scanner;
/*
논리연산자
- 형태: ||(Logical OR) , && (Logical AND) ( |,& )
- 좌우측의항이 논리형데이타이다.
- 결과도 논리형데이타이다.
ex> true || false, false && false
*/
public class LogicalOperator {
private static Scanner sc;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
boolean b1, b2;
boolean result;
b1 = true;
b2 = false;
result = b1 || b2;
System.out.println("true || false = "+result);
result = b1 && b2;
System.out.println("true && false = "+result);
b1 = false;
result = b1 || b2;
System.out.println("false || false = "+result);
result = b1 && b2;
System.out.println("flase && false = "+result);
boolean flag = false;
result = !flag;
System.out.println("!false="+result);
//수의 범위 체크
int score = 0;
boolean IsValid ;
sc = new Scanner(System.in); //static으로 상단에서 지정
System.out.println("***Input Your Score***");
score = sc.nextInt();
IsValid = (score >= 0) && (score <= 100);
System.out.println("1. score is "+IsValid);
IsValid = ! ((score<0) || (score>100));
System.out.println("2. score is "+IsValid);
}
}
//------ CH01. RelationalOerator - 관계 연산자 ------ import java.util.Scanner;
/*
관계(비교)연산
- 형태: >,<,>=,<=,==,!=
- 관계연산의 결과값은 논리형 데이타이다(true,false)
*/
public class RelationalOerator {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a = 10;
int b = 20;
boolean result;
Scanner sc = new Scanner(System.in);
a = sc.nextInt();
result = a > b;
System.out.println("10 > 20 = "+result);
result = a == b;
System.out.println("10 == 20 = "+result);
result = a != b;
System.out.println("10 != 20 = "+result);
}
}
//------ CH01. UnaryOperator - 단항 연산자 ------ /*
단항연산자
- 증가,감소연산자
ex> i++ , i-- , ++i , --i
-자기자신의값을 정수 1만큼 증가시키거나 감소시키는
연산자
*/
public class UnaryOperator {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int i=0;
System.out.println("i = "+ i);
System.out.println("i = "+ i++);
System.out.println("i = "+ ++i);
int i1=4, j1=4;
int result1, result2;
result1 = ++i1;
result2 = j1++;
System.out.println("i1 = "+i1);
System.out.println("j1 = "+j1);
System.out.println("r1 = "+result1);
System.out.println("r2 = "+result2);
}
}
//------ CH01. VariableDeclare - 다양한 표현식 ------ public class VariableDeclare{
public static void main(String[] args){
//자바의 단문주석
/*
자바의 장문주석1
자바의 장문주석2
*/
/*
자바변수의선언
- 형태 : 타입 식별자(identifier);
ex> int level;
*/
//1.변수의 선언
int score;
int score1=8888;//선언 & 초기화
int _score2=9999;
int 스코어3=1000;
/*
int 2score;
int my score;
int super*score;
int public;
*/
//2.변수의 초기화
score = 7777;
System.out.println("score="+score);
System.out.println("score1="+score1);
System.out.println("_score="+_score2);
System.out.println("스코어3="+스코어3);
}
}
//------ CH01. VariableTypes - 다양한 타입 ------ //단문주석
/*
장문주석1
장문주석2
*/
/*
변수의선언
- 의미:JVM 에게메모리를할당해달라고
요청하는작업
- 형태:
데이타타입 이름;
ex> int number;
- 변수식별자규직(클래스이름,변수이름,메쏘드이름)
- 영문이나,한글로시작
- 특수문자사용불가(_,$)
- 키워드 사용금지
*/
public class VariableTypes {
public static void main (String[] args){
//1. 논리형(논리형상수 -> T,F는 그 자체 값 바꿀 수 X)
boolean b1, b2;
b1 = true;
b2 = false; //java는 boolean값으로 0,1 지원X
System.out.println ("b1 = "+b1);
System.out.println ("b2 = "+b2);
//2. 문자형
char munja1, munja2, munja3, munja4;
munja1 = 'a';
munja2 = 'ㅁ';
munja3 = '김';
munja4 = 44608;
int munja5 = '김';
System.out.println ("munja1="+munja1);
System.out.println ("munja2="+munja2);
System.out.println ("munja3="+(int)munja3);
System.out.println ("munja4="+munja4);
System.out.println ("munja5="+munja5);
int i=97;
for (i=97; i<123; i++){
System.out.print ((char)i+" ");
}
System.out.println ();
//3. 숫자
//3-1. 정수형 (정수형 상수)
/********byte********/
byte b = 100; //-128~127 (1byte)
/*
4바이트상수에 100을 넣고나서 byte에 넣더라도
byte 범위 안에 감당할 수 있는 값이면 넣어준다.
= 자동casting해준다.
*/
/* byte by;
int ii1 = 100;
by = ii1; //possible loss of precision 이건 int->byte니까 무조건안됨.
*/
/********shotr********/
short s = 200; //-32768~32767 (2byte)
/********int********/
int i1; //(4byte)
i1 = 2147483647; //int범위= -2147483648~2147483647
/*
i1 = 2147483648;
error:integer number too large: 2147483648
*/
/********long********/
long l1 = 2147483648L; //(8byte)
/*
long l1 = 2147483648;
상수는 무조건 4byte로 잡힌 다음에 들어가기 때문에
long으로 선언해도 error, 그래서 숫자 뒤에L써줌
*/
System.out.println ("i1 = "+i1);
System.out.println ("l1 = "+l1);
//3-2. 실수형 (실수형 상수 (0.2, 500.1, 45.12)기본 8byte double)
float f1, f2;
f1 = 3.141592f;
System.out.println ("f1 = "+f1);
double d1;
d1 = 0.012345678;
System.out.println ("d1 = "+d1);
/********String Type (문자열형)********/ String str1, str2;
str1 = "열심히 살자";
str2 = "될 놈은 된다";
String str3 = str1+str2;
System.out.println ("str3 = "+str3);
/* tip: sysout + Ctrl+space = System.out.println();
* cf: Help - KeyAssist*/
}
}
//------ CH01. YearTest - 윤년 출력 ------ import java.util.Scanner;
/*
*
* ① 4로 나누어 떨어지는 해는 우선 윤년으로 하고
② 그 중에서 100으로 나누어 떨어지는 해는 평년으로 하며
③ 다만 400으로 나누어 떨어지는 해는 다시 윤년으로 정하였다
good
String result="";
if(year%4==0 && year%100!=0 || year%400==0) result="윤년";
else result="평년";
System.out.println(year+"년은 "+result+"입니다.");
*/
public class YearTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int year;
String youn_year = null;
Scanner sc = new Scanner(System.in);
year = sc.nextInt();
if (year <= 0){
System.out.println("년도 입력은 양수만 가능합니다.");
return; //해당 경우에 하위 문장을 실행하지 않고 return
}
if (year%4 == 0){
if (year%100 == 0){
if (year%400 == 0){
System.out.println(year+"년도는 윤년 입니다.");
}
else{
System.out.println(year+"년도는 평년 입니다.");
}
}
else{
System.out.println(year+"년도는 윤년 입니다.");
}
}
else{
System.out.println(year+"년도는 평년 입니다.");
}
}
}
'JAVA > 자바실습' 카테고리의 다른 글
| [JAVA] OOP 다형성 - 오버로딩 (0) | 2013.06.12 |
|---|---|
| [JAVA] OOP Encapsulation 캡슐화 (0) | 2013.06.12 |
| [JAVA] OOP BASIC (객체지향 프로그래밍 기초) (0) | 2013.06.12 |
| [JAVA] 자바기본2: For, While 문을 이용한 구구단, 별 찍기, 알파벳 출력 등 (0) | 2013.06.12 |
RECENT COMMENT