重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
程序运行截图:
成都创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站设计、做网站、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的路桥网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
父类Person:
//包括属性(姓名,性别,年龄)
//方法getDetails(),用于显示所有信息
public class Person {
String name;// 姓名
int age;// 年龄
String sex;// 性别
public String getDetails() {
return "姓名:" + name + " ,性别:" + sex + ",年龄:" + age + " 岁";
}
}
创建子类Student:
public class Student extends Person {
//增加属性“专业”
String specialty;// 专业
public Student(String name, String sex, int age, String specialty) {
this.name = name;
this.sex = sex;
this.age = age;
this.specialty = specialty;
}
//重写getDetails()方法
@Override
public String getDetails() {
//在该方法中使用父类的getDetails()方法
return super.getDetails() + ",专业:" + specialty;
}
}
测试:
public static void main(String[] arg) {
Student s = new Student("庄敏", "女", 20, "软件技术");
System.out.println(s.getDetails());
}
package test1;
import java.util.Scanner;
public class Test {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("输入数组1长度");
int n1 = scanner.nextInt();
System.out.println("输入数组1");
String nullString1 = scanner.nextLine();
String numsString1 = scanner.nextLine();
String[] split1 = numsString1.split(" ");
System.out.println("输入数组2长度");
int n2 = scanner.nextInt();
System.out.println("输入数组2");
String nullString2 = scanner.nextLine();
String numsString2 = scanner.nextLine();
String[] split2 = numsString2.split(" ");
System.out.println("输入条件");
String numsString3 = scanner.nextLine();
String[] split3 = numsString3.split(" ");
int start = Integer.valueOf(split3[0]);
int mubiao = Integer.valueOf(split3[1]);
int number = Integer.valueOf(split3[2]);
for(int i = (mubiao-1),y=(start-1),c = 0 ; c number ; i++,y++,c++){
split1[y] = split2[i];
}
for(int i =0 ; i split1.length ; i++){
System.out.print(split1[i]+" ");
}
}
}
最简单的java代码肯定就是这个了,如下:
public class MyFirstApp
{
public static void main(String[] args)
{
System.out.print("Hello world");
}
}
“hello world”就是应该是所有学java的新手看的第一个代码了。如果是零基础的新手朋友们可以来我们的java实验班试听,有免费的试听课程帮助学习java必备基础知识,有助教老师为零基础的人提供个人学习方案,学习完成后有考评团进行专业测试,帮助测评学员是否适合继续学习java,15天内免费帮助来报名体验实验班的新手快速入门java,更好的学习java!
public class Person {
public String name;
public int age;
public Person(String name, int age){
this.name = name;
this.age = age;
}
public Person(String name){
this.name = name;
this.age = 20;
}
public void work(){
System.out.println("我正在工作!");
}
public static void main(String[] args) {
Person p = new Person("I");
p.work();
}
}
-------------------------------------------------------------
public class Person {
public String name;
public int age;
public Person(String name, int age){
this(name);
this.age = age;
}
public Person(String name){
this.name = name;
this.age = 20;
}
public void work(){
System.out.println("我正在工作!");
}
public static void main(String[] args) {
Person p = new Person("I");
p.work();
}
}
class Student extends Person{
public Student(String name){
super(name);
}
public void work(){
System.out.println("学生在学习!");
}
}
class Teacher extends Person{
public Teacher(String name){
super(name);
}
public void work(){
System.out.println("老师在授课!");
}
}