/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*//**
*
* @author Administrator
*/
import java.util.Scanner;/*
* To change this template, choose Tools | Templates and open the template in
* the editor.
*/
/**
*
* @author Administrator
*/
public class Decreasing { String number[];
String name[];
int scores[];
int n; public void init(String number1[], String name1[], int scores1[]) {
System.out.println("How many students do you want to input?");
Scanner str = new Scanner(System.in);
n = str.nextInt();
scores1 = new int[n];
number1 = new String[n];
name = new String[n];
System.out.println("Please input " + n + " students' number,name and scores");
Scanner string = new Scanner(System.in);
for (int i = 0; i < n; i++) {
number1[i] = string.nextLine();
name1[i] = string.nextLine();
scores1[i] = string.nextInt();
}
} public void sort(String number2[], String name2[], int scores2[]) { String numbertemp, nametemp;
int scorestemp;
for (int i = 0; i < n - 1; i++) {
for (int j = 1; j < n; j++) {
if (scores2[i] < scores2[j]) {
numbertemp = number2[i];
number2[i] = number2[j];
number2[j] = numbertemp;
nametemp = name2[i];
name2[i] = name2[j];
name2[j] = nametemp;
scorestemp = scores2[i];
scores2[i] = scores2[j];
scores2[j] = scorestemp;
}
}
}
} public void output(String number3[], String name3[], int scores3[]) {
for (int i = 0; i < n; i++) {
System.out.println(name3[i] + " " + number3[i] + " " + scores3[i]);
}
} public static void main(String args[]) {
Decreasing application = new Decreasing();
application.init(application.number, application.name, application.scores);
//application.sort(application.number, application.name, application.scores);
// application.output(application.number, application.name, application.scores);
}
};
* To change this template, choose Tools | Templates
* and open the template in the editor.
*//**
*
* @author Administrator
*/
import java.util.Scanner;/*
* To change this template, choose Tools | Templates and open the template in
* the editor.
*/
/**
*
* @author Administrator
*/
public class Decreasing { String number[];
String name[];
int scores[];
int n; public void init(String number1[], String name1[], int scores1[]) {
System.out.println("How many students do you want to input?");
Scanner str = new Scanner(System.in);
n = str.nextInt();
scores1 = new int[n];
number1 = new String[n];
name = new String[n];
System.out.println("Please input " + n + " students' number,name and scores");
Scanner string = new Scanner(System.in);
for (int i = 0; i < n; i++) {
number1[i] = string.nextLine();
name1[i] = string.nextLine();
scores1[i] = string.nextInt();
}
} public void sort(String number2[], String name2[], int scores2[]) { String numbertemp, nametemp;
int scorestemp;
for (int i = 0; i < n - 1; i++) {
for (int j = 1; j < n; j++) {
if (scores2[i] < scores2[j]) {
numbertemp = number2[i];
number2[i] = number2[j];
number2[j] = numbertemp;
nametemp = name2[i];
name2[i] = name2[j];
name2[j] = nametemp;
scorestemp = scores2[i];
scores2[i] = scores2[j];
scores2[j] = scorestemp;
}
}
}
} public void output(String number3[], String name3[], int scores3[]) {
for (int i = 0; i < n; i++) {
System.out.println(name3[i] + " " + number3[i] + " " + scores3[i]);
}
} public static void main(String args[]) {
Decreasing application = new Decreasing();
application.init(application.number, application.name, application.scores);
//application.sort(application.number, application.name, application.scores);
// application.output(application.number, application.name, application.scores);
}
};
number1 = new String[n];
name = new String[n];
这里的name应该为name1. 可是改了之后还是不行。
number1[i] = s.nextLine();
name1[i] = s.nextLine();
scores1[i] = s.nextInt();
}主要是在这个输入这里出错。。只能输入两次,然后就出错了。
import java.util.Scanner;public class Decreasing { String number[];
String name[];
int scores[];
int n; public void init(String number1[], String name1[], int scores1[]) {
System.out.println("How many students do you want to input?");
Scanner str = new Scanner(System.in);
n = str.nextInt();
number1 = new String[n];
name1 = new String[n];
scores1 = new int[n];
System.out.println("Please input " + n + " students' number,name and scores");
Scanner string = new Scanner(System.in);
Scanner string1 = new Scanner(System.in);
Scanner string2 = new Scanner(System.in);
for (int i = 0; i < n; i++) {
number1[i] = string.nextLine();
name1[i] = string1.nextLine();
scores1[i] = string2.nextInt();
}
sort(number1,name1,scores1);
} public void sort(String number2[], String name2[], int scores2[]) { String numbertemp, nametemp;
int scorestemp;
for (int i = 0; i < n - 1; i++) {
for (int j = 1; j < n; j++) {
if (scores2[i] < scores2[j]) {
numbertemp = number2[i];
number2[i] = number2[j];
number2[j] = numbertemp;
nametemp = name2[i];
name2[i] = name2[j];
name2[j] = nametemp;
scorestemp = scores2[i];
scores2[i] = scores2[j];
scores2[j] = scorestemp;
}
}
}
System.out.println("result:");
output(number2,name2,scores2); } public void output(String number3[], String name3[], int scores3[]) {
for (int i = 0; i < n; i++) {
System.out.println(name3[i]);
}
} public static void main(String args[]) {
Decreasing application = new Decreasing();
application.init(application.number, application.name, application.scores);
}
}
package com.huawei.ciweb.action.vote;import java.util.Scanner;public class Decreasing
{
String number[];
String name[];
int scores[];
int n;
public void init(String number1[], String name1[], int scores1[])
{
System.out.println("How many students do you want to input?");
Scanner str = new Scanner(System.in);
n = str.nextInt();
scores1 = new int[n];
number1 = new String[n];
name = new String[n];
System.out.println("Please input " + n
+ " students' number,name and scores");
Scanner string = new Scanner(System.in);
for (int i = 0; i < n; i++)
{
number1[i] = string.nextLine();
name1[i] = string.nextLine();
scores1[i] = string.nextInt();
}
}
public void sort(String number2[], String name2[], int scores2[])
{
String numbertemp, nametemp;
int scorestemp;
for (int i = 0; i < n - 1; i++)
{
for (int j = 1; j < n; j++)
{
if (scores2[i] < scores2[j])
{
numbertemp = number2[i];
number2[i] = number2[j];
number2[j] = numbertemp;
nametemp = name2[i];
name2[i] = name2[j];
name2[j] = nametemp;
scorestemp = scores2[i];
scores2[i] = scores2[j];
scores2[j] = scorestemp;
}
}
}
}
public void output(String number3[], String name3[], int scores3[])
{
for (int i = 0; i < n; i++)
{
System.out.println(name3[i] + " " + number3[i] + " " + scores3[i]);
}
}
public static void main(String args[])
{
Decreasing application = new Decreasing();
application.init(application.number,
application.name,
application.scores);
//application.sort(application.number, application.name, application.scores);
// application.output(application.number, application.name, application.scores);
}
}