Dek-D.com ใช้คุกกี้เพื่อพัฒนาประสบการณ์ของ
ผู้ใช้ให้ดียิ่งขึ้น เรียนรู้เพิ่มเติมที่นี่
ยอมรับ

ใครเก่ง ภาษา จาวา ช่วยผมหน่อยครับ T^T

ตั้งกระทู้ใหม่
ตั้งกระทู้ใหม่
import java.util.Arrays;
public class MathGame180 {
    private static final int[] Int = null;
public static void main(String[] args) {
    {
//this program requires two arguments on the command line
        if (args.length == 6) {
            //convert strings to numbers
            int a = Integer.valueOf(args[0]).intValue();
            int b = Integer.valueOf(args[1]).intValue();
            int c = Integer.valueOf(args[2]).intValue();
            int d = Integer.valueOf(args[3]).intValue();
            int e = Integer.valueOf(args[4]).intValue();
            int f = Integer.valueOf(args[5]).intValue();
            
            
            b = Math.abs(b);
            c = Math.abs(c);
            d = Math.abs(d);
            e = Math.abs(e);
            
            
         // เอาค่าที่ได้ 4 ตัวใส่อะเรย์ ดังนั้นที่เอาไปประมวลผลอาจจะใช้จากอะเรย์หรือตัวแปรก็ได้
            int[] Integer = {a ,b ,c ,d ,e};  
             
            System.out.print("The set of number: ");
    // ตัวอย่างการวนดึงค่าในอะเรย์มาโชว์
    for (int i=0; i<Integer.length; i++){
    System.out.print(Integer[i]+" ");
    }
    System.out.println();
    // ลอง sort อะเรย์ที่เก็บค่าโดยใช้เมทธ็อด sort ทำให้ค่าในอะเรย์เรียงจากน้อยไปมาก
    Arrays.sort(Integer);
    System.out.print("The set of number after sort: ");
    // พิมพ์ค่าออกมาอีกซักทีซิ๊
    for (int i=0; i<Integer.length; i++){
    System.out.print(Integer[i]+" ");
   
    }
    System.out.println();
    System.out.println();
     
   
   
//do some arithmetic
   
     System.out.println("a + b = " + a - c); ผมเอาค่าที่ได้จากการ sort จาก arrays มาบวกกัน ปรากฏว่าตอนรัน มันบวกกันไม่ได้ ช่วยดูให้หน่อยครับ 
           
        }else{
            System.out.println("This program requires six command-line arguments.");
        }
        }
    }
}

แสดงความคิดเห็น

>