import java.io.*;
class chenjiguanlixitong
{
static String [][] chengji=new String [4][6];
static int DC_scroe,JAVA_scroe,English_score;
static int Total_scroe;
static String name="";
public static void anykey_f()
{
char tChar;
System.out.println(" 按任意键继续 ... ");
try{
tChar=(char)System.in.read();
}catch(IOException e){}
}
public static void input()throws UnsupportedEncodingException{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in,"UTF-8"));
for(int i=0;i<=3;i++)
{System.out.print("-------------------------------\n");
System.out.println("请输入学生的学号 :");
System.out.flush();
try{chengji[i][0]=in.readLine();
}catch(IOException e){}
System.out.println("请输入学生的姓名 :");
System.out.flush();
try{chengji[i][1]=in.readLine();
}catch(IOException e){}
System.out.println("请输入学生的DC成绩 :");
System.out.flush();
try{chengji[i][2]=in.readLine();
}catch(IOException e){}
System.out.println("请输入学生的JAVA成绩 :");
System.out.flush();
try{chengji[i][3]=in.readLine();
}catch(IOException e){}
System.out.println("请输入学生的English成绩 :");
System.out.flush();
try{chengji[i][4]=in.readLine();
}catch(IOException e){}
}
anykey_f();
}
public static void count(){
for(int i=0;i<=3;i++) //将数据转化成int型,将进行加法计算
{
DC_scroe=Integer.valueOf(chengji[i][2]).intValue();
JAVA_scroe=Integer.valueOf(chengji[i][3]).intValue();
English_score=Integer.valueOf(chengji[i][4]).intValue();
Total_scroe=DC_scroe+JAVA_scroe+English_score;
chengji[i][5]=String.valueOf(Total_scroe);
}
for(int i=0;i<=3;i++)
{
System.out.print("-------------------------\n");
System.out.println("学生 :"+chengji[i][1]+" 成绩总分为 "+chengji[i][5]);
}
anykey_f();
}
public static void bubble_sort(){//冒泡排序
int temp,flag;
int size=4;
int [] total_scroe=new int[4];
String[] temp2;
for(int i=0;i <=size-1;i++){
total_scroe[i]=Integer.valueOf(chengji[i][5]).intValue();
}
for(int i=0;i<size-1;i++){ //将数据两两比较,将大的置于前
flag=0;
for(int j=0;j <size-i-1;j++)
if(total_scroe[j] <total_scroe[j+1]){
flag=1;
temp=total_scroe[j+1];
total_scroe[j+1]=total_scroe[j];
total_scroe[j]=temp;
temp2=chengji[j+1];
chengji[j+1]=chengji[j];
chengji[j]=temp2;
}
if(flag!=1)
break;
}
System.out.println("按总分排序结果 :");
for(int i=0;i<=3;i++){
System.out.println(chengji[i][1]+"成绩总分:"+total_scroe[i]);
}
anykey_f();
}
public static void selection_sort()//选择排序
{
int temp=0;
int [] total_scroe=new int[4];
for(int i=0;i<=3;i++){
total_scroe[i]=Integer.valueOf(chengji[i][5]).intValue();
}
int base=0,compare=0,max=0,size=4;
String [] temp2;
for(base=0;base<size-1;base++){ //将目前数据与后面数据中最大的对调
max=base;
for(compare=base+1;compare<size;compare++)
if(total_scroe[compare]>total_scroe[max])
max=compare;
temp=total_scroe[max];
total_scroe[max]=total_scroe[base];
total_scroe[base]=temp;
temp2=chengji[max];
chengji[max]=chengji[base];
chengji[base]=temp2;
}
System.out.println("按总分排序结果 :");
for(int i=0;i<=3;i++){
System.out.println(chengji[i][1]+"成绩总分:"+total_scroe[i]);
}
anykey_f();
} public static void query() throws UnsupportedEncodingException{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in,"UTF-8"));
String st="";
int k;
System.out.print("------------------------------\n");
System.out.print(" 请输入要查询学生的学号 ");
System.out.flush();
try{st=in.readLine();}catch(IOException e){
}
for(int i=0;i<=3;i++)
{ int flag=0;
if(chengji[i][0].equals(st))
{ flag=1;
k=i;
System.out.println("学号 :"+chengji[k][0]);
System.out.println("姓名 :"+chengji[k][1]);
System.out.println("DC成绩 :"+chengji[k][2]);
System.out.println("JAVA成绩 :"+chengji[k][3]);
System.out.println("English成绩 :"+chengji[k][4]);
System.out.println("总分 :"+chengji[k][5]);
}
if(flag!=0)
break;
if(i==3)
System.out.println("无此信息记录,请重新输入...");
}
anykey_f();
}
public static void main (String[] args) throws UnsupportedEncodingException{ //主函数
BufferedReader in=new BufferedReader(new InputStreamReader(System.in,"UTF-8"));
String op="";
int option=0;
chenjiguanlixitong obj=new chenjiguanlixitong();
do{
System.out.println("*********学生成绩管理系统**********");
System.out.println(" <1>输入 ");
System.out.println(" <2>总分统计 ");
System.out.println(" <3>信息查询 ");
System.out.println(" <4>总分排序(冒泡排序) ");
System.out.println(" <5>总分排序(选择排序) ");
System.out.println(" <6>退出 ");
System.out.println("***********************************");
op="";
try{
op=in.readLine();
}catch(IOException e){}
option=0;
try{
option=Integer.valueOf(op).intValue();
}catch(NumberFormatException e){}
System.out.println("");
switch(option){
case 1:
obj.input();//输入函数
break;
case 2:
obj.count();//统计总分函数
break;
case 3:
obj.query();//查询函数
break;
case 4:
obj.bubble_sort(); //冒泡排序函数
break;
case 5:
obj.selection_sort(); //选择排序函数
break;
case 6:
System.exit(0); //退出程序
}
}while(true);
}
}
中文输出乱码。 该用什么方法转换成UTF-8``` 代码中的那个好像不顶用...求助```
class chenjiguanlixitong
{
static String [][] chengji=new String [4][6];
static int DC_scroe,JAVA_scroe,English_score;
static int Total_scroe;
static String name="";
public static void anykey_f()
{
char tChar;
System.out.println(" 按任意键继续 ... ");
try{
tChar=(char)System.in.read();
}catch(IOException e){}
}
public static void input()throws UnsupportedEncodingException{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in,"UTF-8"));
for(int i=0;i<=3;i++)
{System.out.print("-------------------------------\n");
System.out.println("请输入学生的学号 :");
System.out.flush();
try{chengji[i][0]=in.readLine();
}catch(IOException e){}
System.out.println("请输入学生的姓名 :");
System.out.flush();
try{chengji[i][1]=in.readLine();
}catch(IOException e){}
System.out.println("请输入学生的DC成绩 :");
System.out.flush();
try{chengji[i][2]=in.readLine();
}catch(IOException e){}
System.out.println("请输入学生的JAVA成绩 :");
System.out.flush();
try{chengji[i][3]=in.readLine();
}catch(IOException e){}
System.out.println("请输入学生的English成绩 :");
System.out.flush();
try{chengji[i][4]=in.readLine();
}catch(IOException e){}
}
anykey_f();
}
public static void count(){
for(int i=0;i<=3;i++) //将数据转化成int型,将进行加法计算
{
DC_scroe=Integer.valueOf(chengji[i][2]).intValue();
JAVA_scroe=Integer.valueOf(chengji[i][3]).intValue();
English_score=Integer.valueOf(chengji[i][4]).intValue();
Total_scroe=DC_scroe+JAVA_scroe+English_score;
chengji[i][5]=String.valueOf(Total_scroe);
}
for(int i=0;i<=3;i++)
{
System.out.print("-------------------------\n");
System.out.println("学生 :"+chengji[i][1]+" 成绩总分为 "+chengji[i][5]);
}
anykey_f();
}
public static void bubble_sort(){//冒泡排序
int temp,flag;
int size=4;
int [] total_scroe=new int[4];
String[] temp2;
for(int i=0;i <=size-1;i++){
total_scroe[i]=Integer.valueOf(chengji[i][5]).intValue();
}
for(int i=0;i<size-1;i++){ //将数据两两比较,将大的置于前
flag=0;
for(int j=0;j <size-i-1;j++)
if(total_scroe[j] <total_scroe[j+1]){
flag=1;
temp=total_scroe[j+1];
total_scroe[j+1]=total_scroe[j];
total_scroe[j]=temp;
temp2=chengji[j+1];
chengji[j+1]=chengji[j];
chengji[j]=temp2;
}
if(flag!=1)
break;
}
System.out.println("按总分排序结果 :");
for(int i=0;i<=3;i++){
System.out.println(chengji[i][1]+"成绩总分:"+total_scroe[i]);
}
anykey_f();
}
public static void selection_sort()//选择排序
{
int temp=0;
int [] total_scroe=new int[4];
for(int i=0;i<=3;i++){
total_scroe[i]=Integer.valueOf(chengji[i][5]).intValue();
}
int base=0,compare=0,max=0,size=4;
String [] temp2;
for(base=0;base<size-1;base++){ //将目前数据与后面数据中最大的对调
max=base;
for(compare=base+1;compare<size;compare++)
if(total_scroe[compare]>total_scroe[max])
max=compare;
temp=total_scroe[max];
total_scroe[max]=total_scroe[base];
total_scroe[base]=temp;
temp2=chengji[max];
chengji[max]=chengji[base];
chengji[base]=temp2;
}
System.out.println("按总分排序结果 :");
for(int i=0;i<=3;i++){
System.out.println(chengji[i][1]+"成绩总分:"+total_scroe[i]);
}
anykey_f();
} public static void query() throws UnsupportedEncodingException{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in,"UTF-8"));
String st="";
int k;
System.out.print("------------------------------\n");
System.out.print(" 请输入要查询学生的学号 ");
System.out.flush();
try{st=in.readLine();}catch(IOException e){
}
for(int i=0;i<=3;i++)
{ int flag=0;
if(chengji[i][0].equals(st))
{ flag=1;
k=i;
System.out.println("学号 :"+chengji[k][0]);
System.out.println("姓名 :"+chengji[k][1]);
System.out.println("DC成绩 :"+chengji[k][2]);
System.out.println("JAVA成绩 :"+chengji[k][3]);
System.out.println("English成绩 :"+chengji[k][4]);
System.out.println("总分 :"+chengji[k][5]);
}
if(flag!=0)
break;
if(i==3)
System.out.println("无此信息记录,请重新输入...");
}
anykey_f();
}
public static void main (String[] args) throws UnsupportedEncodingException{ //主函数
BufferedReader in=new BufferedReader(new InputStreamReader(System.in,"UTF-8"));
String op="";
int option=0;
chenjiguanlixitong obj=new chenjiguanlixitong();
do{
System.out.println("*********学生成绩管理系统**********");
System.out.println(" <1>输入 ");
System.out.println(" <2>总分统计 ");
System.out.println(" <3>信息查询 ");
System.out.println(" <4>总分排序(冒泡排序) ");
System.out.println(" <5>总分排序(选择排序) ");
System.out.println(" <6>退出 ");
System.out.println("***********************************");
op="";
try{
op=in.readLine();
}catch(IOException e){}
option=0;
try{
option=Integer.valueOf(op).intValue();
}catch(NumberFormatException e){}
System.out.println("");
switch(option){
case 1:
obj.input();//输入函数
break;
case 2:
obj.count();//统计总分函数
break;
case 3:
obj.query();//查询函数
break;
case 4:
obj.bubble_sort(); //冒泡排序函数
break;
case 5:
obj.selection_sort(); //选择排序函数
break;
case 6:
System.exit(0); //退出程序
}
}while(true);
}
}
中文输出乱码。 该用什么方法转换成UTF-8``` 代码中的那个好像不顶用...求助```
你为什么要指定读入时的编码方式呢?
默认的不行吗?