九九乘法表
public class cfb {
public static void main(String arg[]){
cfb1();
cfb2();
cfb3();
cfb4();
}
private static void cfb1(){
for(int i=1;i<=9;i++){
for(int j=1;j<=i;j++){
System.out.print(+i+"*"+j+"="+i*j+"\t");
}
System.out.println();
}
}
private static void cfb2(){
for(int i=9;i>=1;i--){
for(int j=1;j<=i;j++){
System.out.print(j+"*"+i+"="+i*j+"\t");
}
System.out.println();
}
}
private static void cfb3(){
for(int i=1;i<=9;i++){
for(int j=i;j<9;j++){
System.out.print("\t");
}
for(int j=i;j>0;j--){
if((i*j)<10)
System.out.print(" "+j+"*"+i+"="+i*j+"\t");
else
System.out.print(+j+"*"+i+"="+i*j+"\t");
}
System.out.println();
}
}
private static void cfb4(){
for(int i=1;i<=9;i++){
for(int j=0;j<i-1;j++){
System.out.print("\t");
}
for(int j=i;j<10;j++){
if((i*j)<10)
System.out.print(" "+j+"*"+i+"="+i*j+"\t");
else
System.out.print(+j+"*"+i+"="+i*j+"\t");
}
System.out.println();
}
}
}
学生成绩查询
public class Student {
int no;
String name;
int english;
int math;
int pe;
public Student(int no, String name, int english, int math, int pe){
this.no = no;
this.name = name;
this.english = english;
this.math = math;
this.pe = pe;
}
public int getno(){
return no;
}
public void setno(int no){
this.no = no;
}
public String getname(){
return name;
}
public void setname(String name){
this.name = name;
}
public int getenglish(){
return english;
}
public void setenglish(int english){
this.english = english;
}
public int getmath(){
return math;
}
public void setmath(int math){
this.math = math;
}
public int getpe(){
return pe;
}
public void setpe(int pe){
this.pe = pe;
}
}
import java.util.Scanner;
public class chaxun {
public static void mzcx(Student[] stu){
System.out.print("请输入你想要查询的学生姓名;");
Scanner sc = new Scanner(System.in);
String name = sc.next();
for(int i=0;i<=stu.length-1;i++){
if(stu[i].name.contains(name)==true){
System.out.println(stu[i].name+"学生的成绩为:");
System.out.println("英语:"+stu[i].english+" 数学:"+stu[i].math+" 体育:"+stu[i].pe);
}
}
}
public static void bjgcx(Student[] stu){
int englishno = 0;
int mathno = 0;
int peno = 0;
System.out.print("英语不及格的有:");
for(int i=0;i<=stu.length-1;i++){
if(stu[i].english<60){
englishno++;
System.out.print(" "+stu[i].name+" ");
}
}System.out.println(" 总共有"+englishno+"人");
System.out.print("数学不及格的有:");
for(int i=0;i<=stu.length-1;i++){
if(stu[i].math<60){
mathno++;
System.out.print(" "+stu[i].name+" ");
}
}System.out.println(" 总共有"+mathno+"人");
System.out.print("体育不及格的有:");
for(int i=0;i<=stu.length-1;i++){
if(stu[i].pe<60){
peno++;
System.out.print(" "+stu[i].name+" ");
}
}System.out.println(" 总共有"+peno+"人");
}
public static void main(String arg[]){
Student[] stu = new Student[5];
stu[0] = new Student(2017011,"张散",50,57,44);
stu[1] = new Student(2017012,"李思",55,70,80);
stu[2] = new Student(2017013,"王武",59,80,90);
stu[3] = new Student(2017014,"劳六",80,90,92);
stu[4] = new Student(2017015,"张无忌",91,95,57);
bjgcx(stu);
mzcx(stu);
}
}
图形
public abstract class Graphical {
public abstract double perimeter();//周长
public abstract double area();//面积
// public abstract String color();//颜色
public abstract String toString();
}
public class Circle extends Graphical{
private double radius;
private double PI=3.14;
public Circle(double radius){
this.radius=radius;
}
@Override
public double perimeter() {
// TODO Auto-generated method stub
return 2*PI*radius;
}
@Override
public double area() {
// TODO Auto-generated method stub
return PI*radius*radius;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return "半径:"+radius+"\t"+"周长:"+perimeter();
}
// @Override
// public String color(int color) {
// // TODO Auto-generated method stub
// return null;
// }
}
public class Rectangle extends Graphical{
private double height;
private double width;
public Rectangle(double height,double width){
this.height=height;
this.width=width;
}
@Override
public double perimeter() {
// TODO Auto-generated method stub
return 2*(height+width);
}
@Override
public double area() {
// TODO Auto-generated method stub
return height*width;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return "长:"+height+"\t"+"宽"+width;
}
}
public class Square extends Graphical {
private double side;
public Square(double side){
this.side=side;
}
@Override
public double perimeter() {
// TODO Auto-generated method stub
return 4*side;
}
@Override
public double area() {
// TODO Auto-generated method stub
return side*side;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return "边长:"+side;
}
}
public class Test2 implements Comparable {
public static void main(String[] args) {
Test2 com=new Test2();
double[] li=new double[10];
li[0]=new Circle(2).area();
li[1]=new Circle(3).area();
li[2]=new Rectangle(8,2).area();
li[3]=new Rectangle(4,5).area();
li[4]=new Square(4).area();
li[5]=new Square(9).area();
System.out.println(com.compareTo(li));
}
}