Java Double類compareTo()方法與示例

雙類compareTo()方法 (Double class compareTo() method)

  • compareTo() method is available in java.lang package.

    compareTo()方法在java.lang包中可用。

  • compareTo() method is used to check equality or inequality for this Double-object against the given Double-object mathematically or in other words, we can say this method is used to compare two Double objects.

    compareTo()方法用于在數學上檢查該Double對象與給定Double對象的相等性或不相等性,換句話說,可以說此方法用于比較兩個Double對象。

  • compareTo() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    compareTo()方法是一種非靜態方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

  • compareTo() method does not throw an exception at the time of comparing Double-object.

    在比較Double-object時, compareTo()方法不會引發異常。

Syntax:

句法:

    public int compareTo(Double value2);

Parameter(s):

參數:

  • Double value2 – represents the Double object to compare with.

    Double value2-表示要比較的Double對象。

Return value:

返回值:

The return type of this method is int, it returns an integer value. It returns 0 if value2 is mathematically equal to value1 (this object), it returns value < 0 if value2 is mathematically greater than value1 (this object), it returns value > 0 if value2 is mathematically less than value1 (this object).

此方法的返回類型為int ,它返回一個整數值。 它返回0,如果值2是數學上等于值1(該對象),則返回值<0,如果是數值2比數學VALUE1(此對象)時,它返回值> 0,如果值2小于值1數學上更小(該對象)。

Example:

例:

// Java program to demonstrate the example 
// of compareTo(Double value2) method of Double class
public class CompareToOfDoubleClass {
public static void main(String[] args) {
// Variables initialization
double d1 = 18.20;
double d2 = 20.20;
// Double instance 
Double value1 = new Double(d1);
Double value2 = new Double(d2);
// It compare two Double objects and placed the 
// result in another variable (compare) of integer type
int compare = value1.compareTo(value2);
// Display result
System.out.println("value1.compareTo(value2): " + compare);
System.out.println();
if (compare == 0)
System.out.println("value1 is equal to value2");
else if (compare < 0)
System.out.println("value1 is less than value2");
else
System.out.println("value1 is greater than value2");
}
}

Output

輸出量

value1.compareTo(value2): -1value1 is less than value2

翻譯自: https://www.includehelp.com/java/double-class-compareto-method-with-example.aspx

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379118.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379118.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379118.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

平院實訓門禁系統導入

這是我的配置&#xff08;如果是Win10最好每一步都管理員身份運行&#xff09; win7 SQLServer2008 VS2012 切記&#xff1a;注意&#xff1a;當你SQLserver創建數據庫和VS連接數據庫的時候得用同一種方式&#xff0c;要么都用window&#xff08;主機名&#xff09;&#xff0…

ffmpeg 解碼音頻(aac、mp3)輸出pcm文件

ffmpeg 解碼音頻&#xff08;aac、mp3&#xff09;輸出pcm文件 播放pcm可以參考&#xff1a; ffplay -ar 48000 -ac 2 -f f32le out.pcm main.c #include <stdio.h> #include <stdlib.h> #include <string.h>#include <libavutil/frame.h> #include …

Jquery getJSON()

getJSON與aspx 準備工作 Customer類 public class Customer{public int Unid { get; set; }public string CustomerName { get; set; }public string Memo { get; set; }public string Other { get; set; }}&#xff08;一&#xff09;ashx Customer customer new Customer { …

北京中信銀行總行地址_中信銀行拉薩分行舉行“存款保險標識”啟用和存款保險條例宣傳活動...

11月NOV中信銀行拉薩分行舉行“存款保險標識”啟用和《存款保險條例》宣傳活動揭牌啟用儀式111月Jul根據人民銀行和總行關于“存款保險標識”啟用工作相關要求&#xff0c;分行行領導高度重視“存款保險標識”啟用和《存款保險條例》宣傳活動工作&#xff0c;按照統一工作部署、…

Java ClassLoader getPackage()方法與示例

ClassLoader類的getPackage()方法 (ClassLoader Class getPackage() method) getPackage() method is available in java.lang package. getPackage()方法在java.lang包中可用。 getPackage() method is used to return the package that has been defined in ClassLoader or t…

C---編寫程序:求出1~1000之間能被7或12整除,但不能同時被二者整除的所有整數,將結果保存在數組中,要求程序數據的輸入、計算和輸出均使用函數實現。

編寫程序&#xff1a;求出1~1000之間能被7或12整除&#xff0c;但不能同時被二者整除的所有整數&#xff0c;將結果保存在數組中&#xff0c;要求程序數據的輸入、計算和輸出均使用函數實現。 編程思路&#xff1a;分別編寫函數input()、cal()、output()實現數據的輸入、計算和…

報告稱我國成最大移民輸出國 將形成投資產業鏈(關注)

時代特有的現象&#xff0c;我們應該予以關注 “現在國內房價這么高&#xff0c;政策也看不清&#xff0c;還不如逢高賣掉之前買的幾套房子&#xff0c;一兩套房子的錢辦個投資移民&#xff0c;趁還年輕&#xff0c;拿到綠卡后享受一下美國本國待遇的高等教育了。”廣州&#x…

轉整型_156.Ruby烘焙大理石豆沙吐司解鎖大理石花紋整型

好看又好吃的大理石豆沙面包。紅豆餡均勻分布在松軟細膩的面包體里&#xff0c;手撕著吃&#xff0c;一層層的甜美與溫柔&#xff5e;關于吐司面包&#xff0c;我公眾號里寫過白吐司(基礎款牛奶吐司&#xff0c;超綿鮮奶油吐司)和全麥吐司(基礎款50%全麥吐司&#xff0c;經典燕…

ffmpeg 解碼視頻(h264、mpeg2)輸出yuv420p文件

ffmpeg 解碼視頻&#xff08;h264、mpeg2&#xff09;輸出yuv420p文件 播放yuv可以參考&#xff1a;ffplay -pixel_format yuv420p -video_size 768x320 -framerate 25 out.yuv main.c #include <stdio.h> #include <stdlib.h> #include <string.h>#includ…

VS2010 快捷鍵 (空格顯示 綠點, Tab 顯示箭頭)

VS2010 有用的快捷鍵 &#xff1a; Ctrl r, ctrl w, 切換空格示。 轉載于:https://www.cnblogs.com/fengye87626/archive/2012/11/21/2780716.html

C---編寫程序:實現一個隨堂測試,能進行加減乘除運算。要求如下:(1)隨機產生兩個1~10的正整數,在屏幕上輸出題目,如:5+3=?(2)學生輸入答案,程序檢查學生輸入答案是否正確,若正確,

編寫程序&#xff1a;實現一個隨堂測試&#xff0c;能進行加減乘除運算。要求如下&#xff1a; 1&#xff09;隨機產生兩個1~10的正整數&#xff0c;在屏幕上輸出題目&#xff0c;如&#xff1a;53&#xff1f; 2&#xff09;學生輸入答案&#xff0c;程序檢查學生輸入答案是…

分析一下mp4格式的trak -> mdia -> minf -> stbl -> stts、stsc 這兩個box信息

分析一下mp4格式的trak -> mdia -> minf -> stbl -> stts、stsc 這兩個box信息 &#xff08;因為這兩個box在音頻trak和視頻trak 下都有的&#xff0c;而且都有一個數組的值是比較繞的&#xff09; 目錄&#xff1a;stts&#xff1a;記錄時間戳的&#xff0c;每個s…

利用SQL注入2分鐘入侵網站

說起流光、溯雪、亂刀&#xff0c;可以說是大名鼎鼎無人不知無人不曉&#xff0c;這些都是小榕哥的作品。每次一提起小榕哥來&#xff0c;我的崇拜景仰就如滔滔江水&#xff0c;連綿不絕~~~~&#xff08;又來了&#xff01;&#xff09; 讓我們崇拜的小榕哥最新又發布了SQL注入…

pip安裝deb_技術|如何在 Ubuntu 上安裝 pip

pip 是一個命令行工具&#xff0c;允許你安裝 Python 編寫的軟件包。 學習如何在 Ubuntu 上安裝 pip 以及如何使用它來安裝 Python 應用程序。有許多方法可以在 Ubuntu 上安裝軟件。 你可以從軟件中心安裝應用程序&#xff0c;也可以從下載的 DEB 文件、PPA(LCTT 譯注&#xff…

assubclass_Java類class asSubclass()方法及示例

assubclass類類asSubclass()方法 (Class class asSubclass() method) asSubclass() method is available in java.lang package. asSubclass()方法在java.lang包中可用。 asSubclass() method casts this Class object to denote a subclass of the class denoted by the given…

VB6.0 怎樣啟用控件comdlg32.ocx

VB6.0 怎樣啟用控件comdlg32.ocx 怎樣啟用控件comdlg32.ocx 2008-10-08 09:32 提問者&#xff1a; nefu_20061617 |瀏覽次數&#xff1a;1502次vbs文件中有代碼Set ComDlg CreateObject("MSComdlg.CommonDialog")運行時發生錯誤ActiveX 部件不能創建對象: MSComdlg.…

Python---爬蟲案例

例1、爬取公眾號文章中的圖片。 1&#xff0c;首先打開要獲取公眾號文章的地址 2&#xff0c;按下F12&#xff0c;再按Ctrl Shift C&#xff0c;然后鼠標移動到圖片位置&#xff0c;然后觀察控制臺中顯示圖片對應的代碼位置 3&#xff0c;分析該位置的代碼段 代碼段如下&…

WinCE驅動開發問題精華集錦(二)

轉自&#xff1a;http://hgh123.blog.163.com/blog/static/5980422120086183115543/ 感謝 我怎么能在PB左邊的定制平臺加進我的驅動呢&#xff1f; 兩種辦法&#xff1a; 1、在platform.bib或者project.bib的MODULES部分添加一條語句&#xff0c;例如&#xff1a; MyDriver.dll…

報錯Unable to resolve target android-5

報錯信息&#xff1a;Error:Unable to resolve target android-X&#xff08;X是一個數字&#xff09; 錯誤分析&#xff1a;這種錯誤一般大部分是SDK 版本不符所造成的&#xff0c;一般會在Ecplise工作空間導入項目時候出現此錯誤&#xff0c;一般提示&#xff1a;Error:Unabl…

matlab盒子分形維數_分形維數--matlab

一維曲線分形維數的matlab程序function DFractalDim(y,cellmax)%求輸入一維信號的計盒分形維數%y是一維信號%cellmax:方格子的最大邊長,可以取2的偶數次冪次(1,2,4,8...),取大于數據長度的偶數%D是y的計盒維數(一般情況下D>1),Dlim(log(N(e))/log(k/e)),if cellmaxerror(cel…