class Shape {
final static double PI=3.1415926;
void s1(int r){
double s1=r*r*PI;
System.out.println("圆形面积:"+s1);
}
void s2(int a,int b){
float s2=a*b;
System.out.println("矩形面积:"+s2);
}
}public class H7_1 extends Shape {
public static void main(String[] args) {
Shape a=new Shape();
a.s1(2);
a.s2(1, 11);
}
}
package holleJAVA;
public class H7_4 {
static int age;
public String toString(){
return "我18岁,我是";
}
public static void main(String[]args){
age=18;
if(age<=18){
System.out.println(new H7_4()+"成年人。");
}
else{
System.out.println(new H7_4()+"未成年人。");
}
}
}
import java.util.Scanner;
public class Ho7_3 {
public static void main(String[] args) {
St e=new St();
System.out.println("请输入用户名:");
Scanner in=new Scanner(System.in);
String name=in.next();
System.out.println("请输入密码:");
Scanner c=new Scanner(System.in);
String word=c.next();
As a=new As();
e.dengru(name,word);
}
}
class St{
void dengru(String a,String b){
if(a.equals("张三")){
if(b.equals("123456")){
System.out.println("-------------\n"+"登录成功");
}
}
}
}
package holleJAVA;
class Past{
double a[]=new double[]{1.98,5.0,0.0,9.9};
}
public class Ho7_4 extends Past{
public static void main(String[]args){
double b[]=new double[]{2.98,5.0,1.0,14.9};
System.out.println("水果名称 水果价格(元/千克)水果重量(千克) 包装费(元/千克) 总价 \n"+"——————————————————————————————————————————————————————————————————");
System.out.print("苹果\t");
Ho7_4 ar=new Ho7_4();
for(int i=0;i<ar.a.length;i++){
System.out.print(ar.a[i]);
System.out.print("\t\t");
}
System.out.println();
System.out.print("精装苹果");
for(int i=0;i<b.length;i++){
System.out.print(b[i]);
System.out.print("\t\t");
}
System.out.println();
System.out.print("——————————————————————————————————————————————————————————————————");
System.out.println();
System.out.print("差价\t\t\t\t\t\t\t");
double j=b[b.length-1]-ar.a[ar.a.length-1];
System.out.print(j);
}
}