切割
今天学了一道字符串替换的问题,又了解到了一个新姿势–trim方法
作用是去除前后两端的空格直到出现字符串为止
如下: String s = “a s f g”; String s1 = s.trim(); System.out.println(s1); 输出结果为”a s f g” 前[……]
class Person{
String name;
int age;
Person(String name,int age){
this.name = name;
this.age = age;
}
void work(){
}
/* 请在这里填写答案 */
public class Ma[……]
题目既详细又简单,按照要求写就行。因为是函数题,我们主函数都不需要写只需要把类方法写好就行
首先是定义shape类作为父类并且提供计算周长和面积的函数
这里因为没有具体图形我们只需要定义方法就可以,后续子类调用面积和周长方法在子类重写就行,符合抽象类的定义(具体方法不用书写,直接在子类重[……]
import java.util.Scanner;
class Student {
int id;
String name;
int age;
public Student(int id, String name, int age) {
this.id = id;
this.name = name;
this.ag[……]
class People{
protected String id;
protected String name;
}
class Student extends People{
protected String sid;
protected int score;
public Student[……]
根据题目要求,先定义一个person类内含private权限的属性,然后是写有参和无参构造函数。无参构造函数要打印”This is constructor”,还要将name,age,gender,id按照name,age,gender,id格式输出。我们观察输出示例
This is const[……]
构造日期类MyDate类,包含年月日,提供相应的get和set函数,提供void print()函数打印日期,提供int compare(MyDate d)测试当前对象和参数对象d的早晚,如果早则返回-1,晚则返回1,相等则返回0
在main函数中,读入两个日期对象,输出第一个日期对象的信息,输出两个[……]
首先定义circle类,成员变量为题目给定。成员方法首先定义无参类型,并且要为变量赋值并打印
class Circle{
private int radius;
this.radius=2;
System.out.println(“this is a constructor”);
}
定[……]
设计一个BankAccount类,这个类包括:
(1)一个int型的balance表时账户余额。
(2)一个无参构造方法,将账户余额初始化为0。
(3)一个带一个参数的构造方法,将账户余额初始化为该输入的参数。
(4)一个getBlance()方法,返回账户余额。
(5)一个withdraw()方法:带一个a[……]