Home / Java week3
Page options

Java week3


 

ถ้าต้องการรับข้อมูล Character,String แล้วใช้ scanner ต้องทำอย่างไร

 

2. รับข้อมูลโดยใช้ scanner เพื่อคำนวณหาพื้นที่สี่เหลี่ยม กับเส้นรอบรูปสี่เหลี่ยม  รับข้อมูล 2 ตัว

    

    public  class Rectangle2 {

    public static void main(String args[]) {
          java.util.Scanner sc;
          sc = new java.util.Scanner(System.in);
          System.out.print("Please Enter High:");

double  h = sc.nextDouble();           

          System.out.print("Please Enter Width:");

          double  w = sc.nextDouble();     

          double  area= h*w;      

          double  line= (h+w)*2;

          System.out.println(“Area = “+area);

          System.out.println(“Line = “+line);

         }

}

 

 

 


    Post a comment

    Your Name or E-mail ID (mandatory)

     

    Note: Your comment will be published after approval of the owner.




     RSS of this page

    Author: Guest   Version: 1.0   Last Edited By: Guest   Modified: 25 Jun 2008