我是java編程的新手。我在這裏如何使用方法char
有問題。你在char
方法中返回什麼來獲得主體中ASCII值的平均值?謝謝!根據它們的ASCII值求平均兩個字符
public static int average(int i,int j)
{
return (i + j)/2;
}
public static double average(double a,double b)
{
return (a + b)/2;
}
public static char average(char first,char second)
{
return ?;
}
public static void main(String[] args)
{
char first = 'a', second = 'b';
int i = 5, j = 12;
double a = 5.5, b = 8.5;
System.out.println("Average of (x,y) is : " + average(first,second));
System.out.println("Average of (a,b) is : " + average(a,b));
System.out.println("Average of (i,j) is : " + average(i,j));
}
一個字符是一個數字,就像一個int 。 –
試試這個答案: http://stackoverflow.com/questions/19388037/converting-characters-to-integers-in-java#answer-19388099 – vvwccgz4lh