JAVA编程题全集(100题及答案)
发布网友
发布时间:2022-04-22 17:36
我来回答
共3个回答
热心网友
时间:2024-02-20 21:11
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
public class demo {
public static void main(String[] args) {
//Y2Q();
//getStudentsMaxMark();
//get5Or6();
//get5Or6Two();
getPAndL();
}
/**
* 第一题
*/
public static void Y2Q(){
System.out.println("英里 千米");
for (int i = 1; i < 11; i++) {
System.out.println(i+" "+i*1.609);
}
}
/**
* 第二题
*/
public static void getStudentsMaxMark(){
System.out.println("输入学生人数!!");
Scanner s = new Scanner(System.in);
int nextInt = s.nextInt();
List<Student> arrayList = new ArrayList<Student>();
for (int i = 0; i < nextInt; i++) {
Student student = new Student();
System.out.println("输入姓名!!");
String name = s.next();
student.setName(name);
System.out.println("输入成绩!!");
int mark = s.nextInt();
student.setMark(mark);
arrayList.add(student);
}
Collections.sort(arrayList, new Comparator<Student>() {
@Override
public int compare(Student o1, Student o2) {
if(o1.getMark() > o2.getMark()) return -1;
else if(o1.getMark() == o2.getMark()) return 0;
else return 1;
}
});
System.out.println("最高分"+arrayList.get(0).getName()+":"+arrayList.get(0).getMark());
s.close();
}
/**
* 第三题
*/
public static void get5Or6(){
List<Integer> al = new ArrayList<Integer>();
for (int i = 100; i <= 1000; i++) {
if(i%5==0 || i%6==0){
al.add(i);
}
}
for (int i = 0; i < al.size(); i++) {
if(i%10==0){
System.out.println();
}
System.out.print(al.get(i)+" ");
}
}
/**
* 第四题
*/
public static void get5Or6Two(){
List<Integer> al = new ArrayList<Integer>();
for (int i = 100; i <= 1000; i++) {
if(i%5==0 || i%6==0){
if(!(i%5==0 && i%6==0))al.add(i);
}
}
for (int i = 0; i < al.size(); i++) {
if(i%10==0){
System.out.println();
}
System.out.print(al.get(i)+" ");
}
}
/**
* 第五题
*/
public static void getPAndL(){
System.out.println("整数 平分 立方");
for (int i = 0; i <= 10; i++) {
System.out.println(i+" "+i*i+" "+i*i*i);
}
}
}
class Student{
private String name;
private int mark;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getMark() {
return mark;
}
public void setMark(int mark) {
this.mark = mark;
}
}
追问谢谢
热心网友
时间:2024-02-20 21:12
public static void main(String[] args) {
public class xxxx{
double a = 1.609;
for(int i=0,i<10;i++){
System.out.println(i + "\t" + i*a);
}
}
}
热心网友
时间:2024-02-20 21:12
急么?明天中午可以给你追问好的