จำนวนเต็มมี 4 ชนิด
1. byte
2. short
3. int
4. long
ทศนิยมมี 2 ชนิด
1. float
2. double
// sumScore.java public class sumScore {     public static void main(String [] args) {        System.out.println(args[0]);        System.out.println("score1= " + args[1]);        System.out.println("score2= " + args[2]);        System.out.println("sum score= " + (Integer.parseInt(args[1])+Integer.parseInt(args[2])));     } } |
DOWNLOAD : sumScore.java
ตัวแปร args[] จะรับข้อมูลเมื่อเราใส่ให้
args[0] - เป็นการอ้างถึงตัวแปร args ลำดับที่1
Integer.parseInt(args[1]) - การเปลี่ยนข้อมูลของตัวแปร ให้เป็น integer
// run on cmd java sumScore "NAME" 10 20 NAME score1= 10 score2= 20 sum score= 30 |
java sumScore "NAME" 10 20 - args[0] = NAME, args[1] = 10, args[2] = 20
sum score= 30 - เมื่อนำ args[1] กับ args[2] มาเปลี่ยนป็นintegerแล้วบวกกัน จะได้คำตอบออกมา