import javautilScanner;
public class Test{
public static void main(String[] args){
Scanner s = new Scanner(Systemin);
Systemoutprintln("请输入10个学生成绩(用空格分隔):");
int[] sco = getScores(s);
for(int i=0;i<scolength-1;i++){
for(int j=0;j<scolength-1-i;j++){
if(sco[j]<sco[j+1]){
int t = sco[j];
sco[j]=sco[j+1];
sco[j+1]=t;
}
}
}
for(int i=0;i<scolength;i++){
Systemoutprint(sco[i]+" ");
}
}
public static int[] getScores(Scanner s){
String str = snextLine();
String[] score = strsplit(" ");
if(scorelength<10){
Systemoutprintln("请输入至少10个成绩:");
return getScores(s);
}
int[] sco=new int[10];
try{
for(int i=0;i<scorelength;i++){
sco[i]=IntegerparseInt(score[i]);
}
}catch(Exception e){
Systemoutprintln("请输入成绩:");
return getScores(s);
}
return sco;
}
}
第一题:<pre t="code" l="java">
public class People
{
private String name;
public String speak(){
return "";
}
public String getName()
{
return name;
}
public void setName(String name)
{
thisname = name;
}
}
public class American extends People
{
private String name;
@Override
public String speak()
{
return "i’m speak English";
}
public String getName()
{
return name;
}
public void setName(String name)
{
thisname = name;
}
}
public class Chinese extends People
{
private String name;
@Override
public String speak()
{
return "我说中国话";
}
public String getName()
{
return name;
}
public void setName(String name)
{
thisname = name;
}
}
import javautilHashMap;
import javautilMap;
public class Demo01
{
public static Map<, > recruit(People[] people)
{
Map<String, String> resultMap = new HashMap<String, String>();
for (People p : people)
{
if ("我说中国话"equals(pspeak()))
resultMapput(pgetName(), "中国人");
else
resultMapput(pgetName(), "美国人");
}
return resultMap;
}
public static void main(String[] args)
{
Chinese chinese01 = new Chinese();
chinese01setName("小明");
Chinese chinese02 = new Chinese();
chinese02setName("小红");
American american = new American();
americansetName("Tom");
People[] peoples = new People[] { chinese01, chinese02, american };
Map<String, String> resultMap = new HashMap<String, String>(3);
resultMap = (Map<String, String>) recruit(peoples);
for (MapEntry<String, String> entry : resultMapentrySet())
{
String key = entrygetKey();
String value = entrygetValue();
Systemoutprintln(key + ":" + value);
}
}
}
/
运行结果
Tom:美国人
小明:中国人
小红:中国人
/ 第二题:<pre t="code" l="java">public class Engineer
{
private String name;
public String writerCode()
{
return "";
}
public String getName()
{
return name;
}
public void setName(String name)
{
thisname = name;
}
}
public class JavaEngineer extends Engineer
{
private String name;
@Override
public String writerCode()
{
return "在写Java代码";
}
public String getName()
{
return name;
}
public void setName(String name)
{
thisname = name;
}
}
public class iOSEngineer extends Engineer
{
private String name;
@Override
public String writerCode()
{
return "在写iOS代码";
}
public String getName()
{
return name;
}
public void setName(String name)
{
thisname = name;
}
}
import javautilHashMap;
import javautilMap;
public class Demo02
{
public static Map<, > recruit(Engineer[] Engineer)
{
Map<String, String> resultMap = new HashMap<String, String>();
for (Engineer e : Engineer)
{
if ("在写Java代码"equals(ewriterCode()))
resultMapput(egetName(), "Java工程师");
else
resultMapput(egetName(), "iOS工程师");
}
return resultMap;
}
public static void main(String[] args)
{
JavaEngineer JavaEngineer01 = new JavaEngineer();
JavaEngineer01setName("Sunny");
JavaEngineer JavaEngineer02 = new JavaEngineer();
JavaEngineer02setName("Jain");
iOSEngineer iOSEngineer = new iOSEngineer();
iOSEngineersetName("Tony");
Engineer[] Engineers = new Engineer[] { JavaEngineer01, JavaEngineer02, iOSEngineer };
Map<String, String> resultMap = new HashMap<String, String>(3);
resultMap = (Map<String, String>) recruit(Engineers);
for (MapEntry<String, String> entry : resultMapentrySet())
{
String key = entrygetKey();
String value = entrygetValue();
Systemoutprintln(key + ":" + value);
}
}
}
/
运行结果:
Sunny:Java工程师
Jain:Java工程师
Tony:iOS工程师
/
以上就是关于JAVA编程题 急求啊全部的内容,包括:JAVA编程题 急求啊、Java编程题、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)