我是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