1. java 字元之間怎麼比大小
//沒看清楚是比較字元了...
字元比較可以直接.
char a='a';
char b='b';
if(a<b) //java會自動給他們判斷UNICAL碼值
System.out.println(a+"<"+b);
//重點 a.compareTo(b)) 要比較的2個字元串
public class wq {
public static void main(String agrs[])
{
String a="aaq";
String b="awq";
System.out.println(a.compareTo(b)); //判斷 b和a的大小.. 大多少 或者 小多少 相等返回0
}
}
2. 在java中怎麼比較三個整數大小例如(a , b, c);並從小到大輸出
public static void main(String args[]) {
Integer a = 2, b = 1, c = 3;
int max, min, middle = 0;
if (a > b) {
max = a;
min = b;
if (max < c) {
middle = a;
max = c;
}
if (min > c) {
middle = b;
min = c;
}
} else {
max = b;
min = a;
middle = c;
if (max < c) {
middle = b;
max = c;
}
if (min > c) {
middle = a;
min = c;
}
}
System.out.println(max + "---" + middle + "====" + min);
}
執行結果:
3. 在java中怎麼比較三個整數大小例如(a,b,c
public class Sort {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("請依次輸入3個數版字權");
int a = scanner.nextInt();
int b = scanner.nextInt();
int c = scanner.nextInt();
if( b > a){
int t = 0;
t = a;
a = b;
b = t;
}
if( c > a){
int t =0;
t = a;
a = c;
c = t;
}
if( c > b){
int t = 0;
t = c;
c = b;
b = t;
}
System.out.println("a = "+ a + " b= " + b + " c= " + c );
}
}
4. 如何用Java比較兩個整數的大小
publicclassHello{
publicstaticvoidmain(String[]args){
容System.out.println(getMax(2,10));
}
publicstaticintgetMax(inta,intb){
returna>b?a:b;
}
}
5. Java中有沒有直接比較兩個整數大小的方法
樓主的意思是比較那種類型的整數?int和long甚至integer都可以用普通的比較符號「<」
,">"," !=" ,"=="來進行比較。
6. 在java中int[] a 怎麼和100比較大小
你是說要把a數組裡面的元素一個個的喝100比較嗎?
System.out.println("列印專數組中所有比100大的屬數");
for(int i=0;i<a.length;a++)
{
if(int[i]>100)
{
System.out.println(a[i]);
}
}
7. java biginteger怎麼比較大小
compareTo方法來比較,小於則返回-1,等於則返回0,大於則返回1
BigIntegera1=newBigInteger("1");
BigIntegera2=newBigInteger("2");
a1.compareTo(a2);
下面的例子顯示math.BigInteger.compareTo()方法的用法
package com.yii;import java.math.*;public class BigIntegerDemo {public static void main(String[] args) {
// create 2 BigInteger objects
BigInteger bi1, bi2;
bi1 = new BigInteger("6");
bi2 = new BigInteger("3");
// create int object
int res;
// compare bi1 with bi2
res = bi1.compareTo(bi2);
String str1 = "Both values are equal ";
String str2 = "First Value is greater ";
String str3 = "Second value is greater";
if( res == 0 )
System.out.println( str1 );
else if( res == 1 )
System.out.println( str2 );
else if( res == -1 )
System.out.println( str3 );
}}
讓我們編譯和運行上面的程序,這將產生以下結果:
First Value is greater
8. JAVA 整形變數之間的比較問題
你對==的理解有錯誤,如果是引用變數,當然比較的是引用變數的值,而引用變數的值就是對象的地址,所以當2個引用變數指向同一個對象時,返回true;而如果是數值型,同樣,只要他們的值相等就返回true。所以不用改
9. JAVA比較數值的大小
publicstaticvoidmain(String[]args){
Scannerinput=newScanner(System.in);
intnum;
intmax=0;
intmin=0;
while(true){
System.out.println("請輸入一個整數「輸入0時結束」:");
num=input.nextInt();
if(num==0){
break;
}
if(num>max){
max=num;
}
if(num<min){
min=num;
}
}
System.out.print("最大值為:"+max+"最小值為:"+min);
}
10. 用java編程 輸入兩個整數並比較它們的大小
演算法給你吧 public double compare(double x,double y)//該函數返回較大的數
{ if (x>y) return x; else return y; }