n import java io import java util Random

  • Slides: 20
Download presentation

자바의 기본 문법 n 예제 import java. io. *; import java. util. Random; public

자바의 기본 문법 n 예제 import java. io. *; import java. util. Random; public class Import. Exam { public static void main(String args[]) { Random rand = new Random(); int rand. Num = rand. next. Int(100); Print. Writer pr = new Print. Writer(System. out); pr. write("난수 : " + rand. Num); pr. close(); } } n 실행결과 4

자바의 기본 문법 n 예제 public static void main(String args[]) { String str. Num

자바의 기본 문법 n 예제 public static void main(String args[]) { String str. Num = "2005. 09"; String str. Bool = "true"; int. Num = Integer. parse. Int(str. Num); float. Num = Float. parse. Float(str. Num); Boolean bool. Obj = Boolean. value. Of(str. Bool); boolean bool = bool. Obj. boolean. Value(); System. out. println("Integer. parse. Int(str. Num) -> " + int. Num); System. out. println("Float. parse. Float(str. Num) -> " + float. Num); System. out. println("Boolean. get. Boolean(str. Bool) -> " + bool); } n 실행결과 6

자바의 기본 문법 n 예제 public static void main(String args[]) { int a =

자바의 기본 문법 n 예제 public static void main(String args[]) { int a = 20; int b = 100; if(a == b) { System. out. println(a + "와 " + b +"는 같다. "); } else { System. out. println(a + "와 " + b +"는 같지 않다. "); } } n 실행결과 9

자바의 기본 문법 n 예제 public static void main(String args[]) { int a =

자바의 기본 문법 n 예제 public static void main(String args[]) { int a = 20; int b = 100; if(a == b) { System. out. println(a + "와 " + b +"는 같다. "); } else if(a < b) { System. out. println(a + "는 " + b +"보다 작다. "); } else { System. out. println(a + "는 " + b +"보다 크다. "); } } n 실행결과 11

자바의 기본 문법 n 예제 public static void main(String args[]) { int a =

자바의 기본 문법 n 예제 public static void main(String args[]) { int a = 0; while(a < 10) { System. out. println("2 * " + a + " = " + (2 * a)); a++; } } n 실행결과 13

자바의 기본 문법 n 예제 public static void main(String args[]) { int a =

자바의 기본 문법 n 예제 public static void main(String args[]) { int a = 0; while(true) { System. out. println("2 * " + a + " = " + (2 * a)); if(a>=9) break; a++; } } n 실행결과 15

자바의 기본 문법 n 예제 public static void main(String args[]) { int a =

자바의 기본 문법 n 예제 public static void main(String args[]) { int a = 100; int b = 20; int c = 0; if(a < b & (c = a - b) > 0) { System. out. println("조건식 [a < b & (c = a - b) > 0]가 참이다. "); }else { System. out. println("조건식 [a < b & (c = a - b) > 0]가 거짓이다. "); } c = 0; if(a > b | (c = a - b) > 0) { System. out. println("조건식 [a < b | (c = a - b) > 0]가 참이다. "); System. out. println("c = " + c); } c = 0; if(a > b || (c = a - b) > 0) { System. out. println("조건식 [a < b | (c = a - b) > 0]가 참이다. "); System. out. println("c = " + c); } } 18