1. Trang chủ
  2. » Công Nghệ Thông Tin

Lập trình hướng đối tượng trong java (Phần 6) doc

6 413 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 6
Dung lượng 263,88 KB

Nội dung

      LẬP TRINH HƢỚ NG ĐÔ ́ I TƢỢNG TRONG JAVA phần 6 III.   N      , t  .                ,  :      ,                   : Byte, Double, Float, Integer, Long, Short : Boolean, Character, Void, Math 1. To mt đi tưng Float f = new Float(25.5);  - C Float(double n) Float(float n) Float(string str) Double(double n) Double(string str) T            2. Cc phƣơng thc thƣng dng cho cc lp kiu s -      nhau byte byteValue() // tr short shortValue() int intValue() long longValue() double doubleValue() float floatValue() Integer intObj = new Integer(25);       int i = intObj.intValue(); // cho i = 25 - l              static byte parseFloat(String str) static short parseShort(String str) static int parseInt(String str) static long parseLong(String str) static double parseDouble(String str) static float parseFloat(String str) String s  int i =Integer.parseInt(s); // cho i = 42 - int compareTo(floatObj/floatVar f ) : so s   , :  = 0 :    =  :   =  :  - boolean equals(floatObj f ) :  =             - string toString() :      .                         java.                        .   , , Integer,    String : Integer i = new Integer(20); System.out.println(i.toString()); - static String toString(var n) :                String s = Integer.toString(25) // Cho chul  - static Float valueOf(String str) :        ,              Integer i = Integer.valueOf(s);       V d :     :  20  sinh >1970  <2100,  import java.io.*; public class Nhap { public static void main (String [] args) throws IOException { DataInputStream kbd = new DataInputStream (System.in); String s = null; String ns = null; // Nhap ho ten while (true) { System.out.print("Nhap Ho va ten : "); s = kbd.readLine(); if ( (s.length() <=20) && (s.length() != 0) ) { System.out.println("Ho va ten la : "+ s); break; } System.out.println("Phai nhap ho ten khong qua 20 ky tu"); } // Nhap nam sinh while (true) { try { System.out.print("Nhap nam sinh : "); s = kbd.readLine(); int i =Integer.parseInt(s); if ((i<=1970) || (i>=2100)) throw new NumberFormatException(); System.out.println("Nam sinh la : "+i); break; } catch (IOException e){} catch(NumberFormatException e){ System.out.println("Ban Phai nhap lai nam sinh trong khoang 1970 den 2100");       } } } }  .lang.Byte, java.lang.Short, java.lang.Integer, java.lang.Double, java.lang.                                    5 MC LC      I.   1.       2.     II.          1.  2.  3.   , M I.    II. NG 1.     2.  III.      1.      2.          3.   () 4.  5.  6.    7. N 8.   IV.      1.        2.     3. T V.      VI.    (   ) (    ) 1. C 2.              6 VII.     VIII.        1.           2.          IX.  1.  2.  3.      ng :  I.  1.       2.      3.      II.  1.     2. Hi 3.    4.   5.         I.     II.   III.   . nam sinh trong khoang 1970 den 2100");       } } } }  .lang.Byte, java. lang.Short, java. lang.Integer, java. lang.Double, java. lang.    .       LẬP TRINH HƢỚ NG ĐÔ ́ I TƢỢNG TRONG JAVA phần 6 III.   N      , t  .               . 20  sinh >1970  <2100,  import java. io.*; public class Nhap { public static void main (String [] args) throws IOException { DataInputStream

Ngày đăng: 12/07/2014, 22:20

TỪ KHÓA LIÊN QUAN

w