急 Java字母排序问题 谢谢大神了,
packagetext;importjava.util.Scanner;classsort{privatecharn,m,y;publicsort(chara,charb...
package text;
import java.util.Scanner;
class sort{
private
char n,m,y;
public
sort(char a,char b,char c)
{
n=a;m=b;y=c;
}
void sort1()
{
char t='x';
if(n>m)
{
t=m;
m=n;
n=t;
}
if(m>y)
{
t=y;
y=m;
m=t;
}
}
void print()
{System.out.println(m,+ n,+ y);
}
};
public class abc {
public static void main(String[] args) {
char[] a=new char[3];
//sort com1=new sort();
Scanner sc= new Scanner(System.in);
String s1=sc.next();
String s2=sc.next();
String s3=sc.next();
for(int i=0;i<3;i++){
a[i]=s1.charAt(i);
}
sort com1=new sort();
com1(a[1],a[2],a[3]);
com1.sort1();
com1.print();
for(int i=0;i<3;i++){
a[i]=s2.charAt(i);
}
sort com2=new sort();
com2(a[1],a[2],a[3]);
com2.sort1();
com2.print();
for(int i=0;i<3;i++){
a[i]=s3.charAt(i);
}
sort com3=new sort();
com3(a[1],a[2],a[3]);
com3.sort1();
com3.print();
// TODO Auto-generated method stub
}
}
xception in thread "main" java.lang.Error: Unresolved compilation problems:
The constructor sort() is undefined
The method com1(char, char, char) is undefined for the type abc
The constructor sort() is undefined
The method com2(char, char, char) is undefined for the type abc
The constructor sort() is undefined
The method com3(char, char, char) is undefined for the type abc
at text.abc.main(abc.java:44)
class sort 起不到作用 为啥 展开
import java.util.Scanner;
class sort{
private
char n,m,y;
public
sort(char a,char b,char c)
{
n=a;m=b;y=c;
}
void sort1()
{
char t='x';
if(n>m)
{
t=m;
m=n;
n=t;
}
if(m>y)
{
t=y;
y=m;
m=t;
}
}
void print()
{System.out.println(m,+ n,+ y);
}
};
public class abc {
public static void main(String[] args) {
char[] a=new char[3];
//sort com1=new sort();
Scanner sc= new Scanner(System.in);
String s1=sc.next();
String s2=sc.next();
String s3=sc.next();
for(int i=0;i<3;i++){
a[i]=s1.charAt(i);
}
sort com1=new sort();
com1(a[1],a[2],a[3]);
com1.sort1();
com1.print();
for(int i=0;i<3;i++){
a[i]=s2.charAt(i);
}
sort com2=new sort();
com2(a[1],a[2],a[3]);
com2.sort1();
com2.print();
for(int i=0;i<3;i++){
a[i]=s3.charAt(i);
}
sort com3=new sort();
com3(a[1],a[2],a[3]);
com3.sort1();
com3.print();
// TODO Auto-generated method stub
}
}
xception in thread "main" java.lang.Error: Unresolved compilation problems:
The constructor sort() is undefined
The method com1(char, char, char) is undefined for the type abc
The constructor sort() is undefined
The method com2(char, char, char) is undefined for the type abc
The constructor sort() is undefined
The method com3(char, char, char) is undefined for the type abc
at text.abc.main(abc.java:44)
class sort 起不到作用 为啥 展开
2个回答
展开全部
用你的思路重新修改了sort类的定义和sort1方法。
package text;
import java.util.Scanner;
class sort {
private char n, m, y;
public sort(char a, char b, char c) {
n = a;
m = b;
y = c;
}
void sort1() {
char t = 'x';
if (n > m) {
t = m;
m = n;
n = t;
}
if (m > y) {
t = y;
y = m;
m = t;
}
if (n > m) {
t = m;
m = n;
n = t;
}
}
void print() {
System.out.println(String.valueOf(n) + String.valueOf(m) + String.valueOf(y));
//System.out.println();
}
};
public class abc {
public static void main(String[] args) {
char[] a = new char[3];
// sort com1=new sort();
Scanner sc = new Scanner(System.in);
String s1 = sc.next();
String s2 = sc.next();
String s3 = sc.next();
for (int i = 0; i < 3; i++) {
a[i] = s1.charAt(i);
}
sort com1 = new sort(a[0], a[1], a[2]);
//com1(a[1], a[2], a[3]);
com1.sort1();
com1.print();
for (int i = 0; i < 3; i++) {
a[i] = s2.charAt(i);
}
sort com2 = new sort(a[0], a[1], a[2]);
//com2(a[1], a[2], a[3]);
com2.sort1();
com2.print();
for (int i = 0; i < 3; i++) {
a[i] = s3.charAt(i);
}
sort com3 = new sort(a[0], a[1], a[2]);
//com3(a[1], a[2], a[3]);
com3.sort1();
com3.print();
// TODO Auto-generated method stub
}
}
追问
大神 ,默默的问一下 输出 m n y 时 为什么要转化为字符串
追答
否则输出的是数字而不是字符
2015-10-17
展开全部
JAVA中传简单类型,是不会返回的,即是值传递的。。。。。。。。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询