close

(Chapter 4) 輸入5筆資料,每筆資料有姓名和體重,輸入體重範圍,如50kg~60kg,找尋符合此條件的所有人。

 

小弟自己測試過2次暫時沒有太嚴重的BUG..若有同學有測試出BUG拜託不(!?)要通知我

雖然我很想補註解啦..但是明天要小考,所以就算了吧(灑花)

第一小題還沒動手,盡量會在禮拜五前趕出來囉!

 

 

import java.util.*;
import java.io.*;

class data
{
  String name;
  double weight;
  data link;
 
  data()
  {
    link = null;
  }
 
  data(String name, double weight)
  {
    this();
    this.name = name;
    this.weight = weight;
  }

  void show()
  {
    System.out.printf("%s\t%.2f\n",name,weight);
  }
}
public class Wdata
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    
    data top = new data();
    data p;
    
    for( int i = 0; i < 5; i++ )
    {
      System.out.printf("plz input NO %d 's name :",i+1);
      String name = sc.next();

      System.out.printf("plz input he(she)'s weight :");
      double weight = sc.nextDouble();
      
      p = new data(name, weight);
      p.link = top.link;
      top.link = p;
    }
    
    System.out.printf("plz input lower limit of the range you want setting :");
    double low = sc.nextDouble();

    System.out.printf("plz input higher limit of the range you want setting :");
    double high = sc.nextDouble();

    System.out.printf("Your serch is %.2f ~ %.2f\n",low, high);
   
    p = top.link;

    while( p != null )
    {
      if(p.weight > low && p.weight < high)  p.show();
      p = p.link;
    }
  }
}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 Icen Zhong 的頭像
    Icen Zhong

    無止盡的Coding地獄

    Icen Zhong 發表在 痞客邦 留言(0) 人氣()