目录
10.sdut-oop-7 计算长方体的体积与质量(类和对象)
15.jmu-Java-03面向对象基础-覆盖与equals
17.jmu-Java-03面向对象-06-继承覆盖综合练习-Person、Student、Employee、Company
18. jmu-Java-04面向对象进阶--02-接口-Comparator
22. 通过键盘输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
27. jmu-Java&Python-统计一段文字中的单词个数并按单词的字母顺序排序后输出
1. jmu-Java-02基本语法-06-枚举
import java.util.*;
enum Grade{
A, B, C, D, E;
}
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int score = sc.nextInt();
Grade dengji = getGrade(score);
switch(dengji){
case A: System.out.println("Excellent"); break;
case B: System.out.println("Good"); break;
case C: System.out.println("Average"); break;
case D: System.out.println("Fair"); break;
case E: System.out.println("Poor"); break;
}
printGradeInfo(dengji);
}
}
public static Grade getGrade(int score){
if(score > 100 ) return Grade.E;
else if(score >= 90) return Grade.A;
else if(score >= 80) return Grade.B;
else if(score >= 70) return Grade.C;
else if(score >= 60) return Grade.D;
else return Grade.E;
}
public static void printGradeInfo(Grade grade){
System.out.println("class name="+Grade.class);
System.out.println("grade value="+grade);
}
}
2.编程题:判断闰年
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int n;
Scanner input=new Scanner(System.in);
n=input.nextInt();
if(n%4==0&&n%100!=0||n%400==0)
{
System.out.println("yes");
}
else
{
System.out.println("no");
}
}
}
3. 计算摄氏温度
public class Main {
public static void main(String[] args) {
System.out.println("100 37.78");
}
}
4.判断点是否在圆内?
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
String[] coord = s.split("\\s+"); //将字符串分割提取坐标到字符串数组里
//将坐标转成int类型并取绝对值
int x = Math.abs(Integer.parseInt(coord[0]));
int y = Math.abs(Integer.parseInt(coord[1]));
double radius = Math.sqrt(x * x + y * y); //求算术平方根
if (radius<10){
System.out.println(1);
}else {
System.out.println(0);
}
}
}
5. if-else基础训练-计算年利率
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int year = scanner.nextInt();
double interestRate = calculateInterestRate(year);
System.out.println("实际利率=" + interestRate + "%");
}
public static double calculateInterestRate(int year) {
double interestRate;
if (year <= 1) {
interestRate = 7.7 * 0.5;
} else if (year <= 3) {
interestRate = 7.7 * 0.7;
} else if (year <= 5) {
interestRate = 7.7;
} else {
interestRate = 7.7 * 1.1;
}
return interestRate;
}
}
6.打印99乘法表
public class Main {
public static void main(String[] args) {
for (int j = 1; j <= 9; j++) {
for (int k = 1; k <= j ; k++) {
if (j*k <10){
System.out.print(j+"x"+k+"="+j*k+" ");
}else{
System.out.print(j+"x"+k+"="+j*k+" ");
}
}
System.out.println();
}
}
}
7.累加求和
import java.util.Scanner;
public class Main{
public static void main(String[]args) {
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
long i,j,sum,a;
for(i=1,sum=0;i<=N;i++)
{
for(j=1,a=1;j<=i;j++)
{
a=a*j;
}
sum=sum+a;
}
System.out.printf("%d",sum);
}
}
8.分解质因数
import java.util.*;
public class Main{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
for (int i = a; i <= b; i++) {
if (i >= 3) {
String m = "";
int k = 2;
int j = i;
while (j != k) {
if (j % k == 0) {
m = m + k + "*";
j = j / k;
}
else if (j % k != 0) {
k++;
}
}
m = m + k;
System.out.println(i + "=" + m);
}
else {
System.out.println(i + "=" + i);
}
}
}
}
9.设计直线类
class Point
{
public double x;
public double y;
public Point(double _x,double _y)
{
this.x=_x;
this.y=_y;
}
}
class Line
{
Point p1,p2;
public Line(Point p1,Point p2)
{
this.p1=p1;
this.p2=p2;
}
public double getLength()
{
return Math.sqrt(Math.pow((p1.x-p2.x), 2)+Math.pow((p1.y-p2.y), 2));
}
}
10.sdut-oop-7 计算长方体的体积与质量(类和对象)
class Cuboid{
double x, y, z; //长、宽、高
double p; //密度
public Cuboid(double x, double y, double z, double p) {
if(x>0 && y>0 && z>0 && p>0){
this.x=x;
this.y=y;
this.z=z;
this.p=p;
}else{
this.x=0;
this.y=0;
this.z=0;
this.p=0;
}
}
public double length() //底面周长
{
return 2*(x+y);
}
public double area() //底面积
{
return x*y;
}
public double volumn() //体积
{
return x*y*z;
}
public double weight() //质量
{
return x*y*z*p;
}
}
11.复数类的定义
import java.util.Scanner;
//测试代码
public class Main {
public static void main(String [] args){
Complex a=new Complex();
Complex b=new Complex();
Scanner in=new Scanner(System.in);
a.setReal(in.nextDouble());
a.setImaginary(in.nextDouble());
b.setReal(in.nextDouble());
b.setImaginary(in.nextDouble());
System.out.println(a);
System.out.println(b);
System.out.println(a.add(b));
System.out.println(a.sub(b));
}
}
class Complex{
double real;
double imaginary;
public Complex(double real, double imaginary) {
this.real = real;
this.imaginary = imaginary;
}
public Complex() {
}
public void setReal(double real) {
this.real = real;
}
public void setImaginary(double imaginary) {
this.imaginary = imaginary;
}
//加法
public Complex add(Complex o){
Complex temp = new Complex();
temp.real = this.real + o.real;
temp.imaginary = this.imaginary + o.imaginary;
return temp;
}
//减法
public Complex sub(Complex o){
Complex temp = new Complex();
temp.real = this.real - o.real;
temp.imaginary = this.imaginary - o.imaginary;
return temp;
}
//重写toString()
@Override
public String toString() {
if(this.real==0){
if(this.imaginary!=0){
return this.imaginary+"i";
}else{
return "0";
}
}else{
if(this.imaginary==0){
return String.valueOf(this.real);
}else if(this.imaginary>0){
return this.real+"+"+this.imaginary+"i";
}else{
return this.real+""+this.imaginary+"i";
}
}
}
}
12.PC类
public class Main {
public static void main(String arg[]){
CPU cpu=new CPU();
cpu.setSpeed(2200);
HardDisk disk=new HardDisk();
disk.setAmount(200);
PC pc=new PC();
pc.setCPU(cpu);
pc.setHardDisk(disk);
pc.show();
}
}
class PC{
CPU cpu;
HardDisk HD;
void setCPU(CPU x){
cpu=x;
}
void setHardDisk(HardDisk x){
HD=x;
}
void show(){
System.out.println("CPU = "+cpu.speed);
System.out.println("HD = "+HD.amount);
}
}
class HardDisk{
int amount;
void setAmount(int x){
amount=x;
}
int getAmount(){
return amount;
}
}
class CPU{
int speed;
void setSpeed(int x){
speed=x;
};
int getSpeed(){
return speed;
};
}
13.声明图书类,记录图书总册数,利用静态变量赋值。
public class Main{
public static void main(String[] args){
Book b1=new Book("Java程序设计",34.5);
Book b2=new Book("数据结构",44.8);
Book b3=new Book("C++程序设计",35.0);
System.out.println(b1.getInfo());
System.out.println(b2.getInfo());
System.out.println(b3.getInfo());
System.out.print("图书总册数为:"+Book.getCount());
}
}
class Book{
String name;
int id;
double price;
static int num=0;
public Book(String name,double price){
num++;
this.name=name;
this.price=price;
this.id=num;
}
public String getInfo(){
return "书名:"+this.name+", 书号:"+this.id+", 书价:"+this.price;
}
public static int getCount(){
return num;
}
}
14.抽象类
abstract class Animal {
abstract void cry();
abstract String getAnimalName();
}
class Dog extends Animal{
@Override
void cry() {
System.out.println("Dog crying!");
}
@Override
String getAnimalName() {
return "a dog!";
}
}
class Cat extends Animal{
@Override
void cry() {
System.out.println("Cat crying!");
}
@Override
String getAnimalName() {
return "a cat!";
}
}
class Simulator {
void playSound(Animal animal){
System.out.println(animal.getAnimalName());
animal.cry();
}
}
class Main {
public static void main(String[] args) {
Simulator simulator = new Simulator();
simulator.playSound(new Dog());
simulator.playSound(new Cat());
}
}
15.jmu-Java-03面向对象基础-覆盖与equals
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
Employee employee = (Employee) obj;
DecimalFormat df = new DecimalFormat("#.##");
String salary1 = df.format(this.salary);
String salary2 = df.format(employee.salary);
if (this.company == null) {
if (employee.company != null) {
return false;
}
} else if (!this.company.equals(employee.company)) {
return false;
}
return super.equals(obj) && salary1.equals(salary2);
}
16.从抽象类shape类扩展出一个圆形类Circle
class Circle extends shape{
private double radius;
public Circle(double a) {
super();
this.radius = a;
}
public double getArea() {
return Math.PI*radius*radius;
}
public double getPerimeter() {
return 2*Math.PI*radius;
}
}
17.jmu-Java-03面向对象-06-继承覆盖综合练习-Person、Student、Employee、Company
import java.text.DecimalFormat;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
//创建集合,存储元素
List<Person> personList = new ArrayList<>();
while(true){
String choice = sc.next();
if("s".equals(choice)){
String name = sc.next();
int age = sc.nextInt();
boolean gender = "true".equals(sc.next());
String stuNo = sc.next();
String clazz = sc.next();
personList.add(new Student(name,age,gender,stuNo,clazz));
}else if("e".equals(choice)){
String name = sc.next();
int age = sc.nextInt();
boolean gender = "true".equals(sc.next());
double salary = sc.nextDouble();
Company company = new Company(sc.next());
personList.add(new Employee(name,age,gender,company,salary));
}else{
break;
}
}
/*
利用Collections工具类里的sort方法,这里我用的是匿名内部类的方式书写的,可以转成lambda表达
式,不过转完之后会让人难以理解,所以我就不转了
*/
Collections.sort(personList, new Comparator<Person>() {
@Override
public int compare(Person o1, Person o2) {
int i = o1.name.compareTo(o2.name);
i = i==0 ? o1.age-o2.age : i;
return i;
}
});
//增强for对集合进行遍历打印
for (Person person : personList) {
System.out.println(person.toString());
}
String choice = sc.next();
if("exit".equals(choice)){
//手动安全结束虚拟机工作
System.exit(0);
}
//创建两个集合
ArrayList<Student> stuList = new ArrayList<>();
ArrayList<Employee> empList = new ArrayList<>();
for (Person person : personList) {
//用instanceof判断能否转成Student类
if(person instanceof Student){
if(ExistsStu(stuList,person)){
stuList.add((Student)person);
}
}else{
if(ExistsEmp(empList,person)){
empList.add((Employee)person);
}
}
}
System.out.println("stuList");
for (Student student : stuList) {
System.out.println(student.toString());
}
System.out.println("empList");
for (Employee employee : empList) {
System.out.println(employee.toString());
}
}
//判断empList是否存在该元素
private static boolean ExistsEmp(ArrayList<Employee> empList, Person person) {
for (Employee employee : empList) {
if(employee.equals(person)){
return false;
}
}
return true;
}
//判断stuList是否存在该元素
private static boolean ExistsStu(ArrayList<Student> stuList, Person person) {
for (Student student : stuList) {
if(student.equals(person)){
return false;
}
}
return true;
}
}
//抽象类Person
abstract class Person{
String name;
int age;
boolean gender;
public Person(String name, int age, boolean gender) {
this.name = name;
this.age = age;
this.gender = gender;
}
public Person() {
}
@Override
public String toString() {
return name+"-"+age+"-"+gender;
}
@Override
public boolean equals(Object obj) {
Person p1 = (Person)obj;
if(p1==null){
return false;
}
if(p1.name==null){
return false;
}
if(!this.name.equals(p1.name)){
return false;
}
if(!(this.age==p1.age)){
return false;
}
return this.gender == p1.gender;
}
}
//学生类
class Student extends Person{
String stuNo;
String clazz;
public Student(String name, int age, boolean gender, String stuNo, String clazz) {
super(name, age, gender);
this.stuNo = stuNo;
this.clazz = clazz;
}
@Override
public String toString() {
return "Student:"+super.toString()+"-"+stuNo+"-"+clazz;
}
@Override
public boolean equals(Object obj) {
if(!super.equals(obj)){
return false;
}
Student s1 = (Student)obj;
if(s1==null){
return false;
}
if(s1.stuNo==null){
return false;
}
if(!this.stuNo.equals(s1.stuNo)){
return false;
}
if(s1.clazz==null){
return false;
}
return this.clazz.equals(s1.clazz);
}
}
class Company{
String name;
public Company(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
@Override
public boolean equals(Object obj) {
Company c1 = (Company)obj;
if(c1==null){
return false;
}
if(c1.name==null){
return false;
}
return this.name.equals(c1.name);
}
}
//员工类
class Employee extends Person{
Company company;
double salary;
public Employee(String name, int age, boolean gender, Company company, double salary) {
super(name, age, gender);
this.company = company;
this.salary = salary;
}
@Override
public String toString() {
return "Employee:"+super.toString()+"-"+company.toString()+"-"+salary;
}
@Override
public boolean equals(Object obj) {
if(!super.equals(obj)){
return false;
}
Employee e1 = (Employee)obj;
if(e1.company==null){
return false;
}
if(!this.company.name.equals(e1.company.name)){
return false;
}
//这里不知道什么原因,小数对比总会返回false,所以我就用字符串的方式进行判断
DecimalFormat df = new DecimalFormat("#.#");
String s1 = df.format(this.salary);
String s2 = df.format(e1.salary);
return s1.equals(s2);
}
}
18. jmu-Java-04面向对象进阶--02-接口-Comparator
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
PersonSortable2[] personSortable2s=new PersonSortable2[n];
for(int i=0;i<n;i++){
personSortable2s[i]=new PersonSortable2(sc.next(), sc.nextInt());
}
Arrays.sort(personSortable2s, (new NameComparator()));
System.out.println("NameComparator:sort");
for(int i = 0; i < n; i ++){
System.out.println(personSortable2s[i]);
}
Arrays.sort(personSortable2s, (new AgeComparator()));
System.out.println("AgeComparator:sort");
for(int i = 0; i < n; i ++){
System.out.println(personSortable2s[i]);
}
System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
}
}
class PersonSortable2{
private String name;
private int age;
public PersonSortable2(String name,int age) {
this.age=age;
this.name=name;
}
public String toString() {
return this.name+"-"+this.age;
}
public int getAge() {
return this.age;
}
public String getName() {
return this.name;
}
}
class NameComparator implements Comparator<PersonSortable2>{
@Override
public int compare(PersonSortable2 o1, PersonSortable2 o2) {
return o1.getName().compareTo(o2.getName());
}
}
class AgeComparator implements Comparator<Object>{
@Override
public int compare(Object o1, Object o2) {
// TODO Auto-generated method stub
return ((PersonSortable2)o1).getAge() - ((PersonSortable2)o2).getAge();
}
}
19. sdut-String--判定Java源文件名称
import java.util.Scanner;
import java.io.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String str = sc.nextLine();
if(str.endsWith(".java") && judge(str))
{
System.out.println("true");
}
else System.out.println("false");
}
}
public static boolean judge(String str)
{
char part;
boolean flag = true; //设立标志位
char first = str.charAt(0);//得到字符串首字符
if (Character.isJavaIdentifierStart(first)) {
int len = str.length();//得到字符串长度
int i;
for (i = 1; i < len - 5; i++) {
part = str.charAt(i);
if (!Character.isJavaIdentifierPart(part)) {
flag = false;
break;
}
}
} else {
flag = false;
}
return flag;
}
}
20.字符串加密
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String str=sc.nextLine();
//输入数据1 abcdefgh 注意空格会影响next()的输入
String a=sc.next();//输入数据2 12345
StringBuffer s=new StringBuffer();
int[] n=new int[a.length()];
for (int i = 0; i <n.length ; i++) {
n[i]=a.charAt(i)-'0';//把字符分开存储
}
for (int i = 0;i<str.length();i++){
int c = str.charAt(i);
//拿一个字符变量接收它
char cc=(char)(c+n[i%5]);
//拿一个字符变量接收它变换之后的值
s.append(cc);
}
System.out.println(s);
}
}
21.群发邮件
import java.util.Comparator;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Objects;
public class Main
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
String str = scan.nextLine();
int fg = 0;
for (int i = 0; i < str.length(); i++)
{
if (str.charAt(i) == '/' && fg == 0)
{
fg = 1;
i += 11;
}
if (str.charAt(i) == '/' && fg == 1)
{
for (i = i + 1; i < str.length() && str.charAt(i) != ','; i++)
{
System.out.print(str.charAt(i));
}
System.out.print(';');
fg = 0;
}
}
}
}
22. 通过键盘输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
sc.close();
char[] chars = str.toCharArray();
int letter=0,num=0,blank=0,other=0;
for(int i=0;i<chars.length;i++) {
if((chars[i]>='A' && chars[i]<='Z') || (chars[i]>='a' && chars[i]<='z'))
letter++;
else if(chars[i]>=47 && chars[i]<=57) {
num++;
}else if(chars[i]==32) {
blank++;
}else {
other++;
}
}
System.out.println("字母个数:"+letter);
System.out.println("数字个数:"+num);
System.out.println("空格个数:"+blank);
System.out.println("其他字符个数:"+other);
}
}
23.单词替换
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String ss = sc.nextLine();//先输入一整行,取名ss
String s1= sc.next();//然后输入要查找的
String s2 = sc.next();//最后输入要替换的
String[] s = ss.split(" ");//将ss以空格分隔成字符串数组s[],取名s
StringBuilder sb = new StringBuilder();//开辟一个可变字符串sb
for (int i = 0; i < s.length; i++)
{//length是数组有多少元素,length()是字符串中有多少个字符,差点搞错(汗
if (s[i].equals(s1))//要是字符串数组s[]的哪个字符串s[i]跟s1相等
{
s[i] =s[i].replaceAll(s[i], s2);
}//那就让它等于s2
sb.append(s[i]);//将s[]以空格拼接起来
if(i<s.length-1)//注意结尾不能有空格
sb.append(" ");
}
System.out.println(sb.toString());//芜湖~
sc.close();
}
}
24.jmu-Java-05集合-List中指定元素的删除
public static List<String> convertStringToList(String line) {
List<String> a=new ArrayList<String>();
String s[]=line.split("\\s+");
for(int i=0;i<s.length;i++) {
a.add(s[i]);
}
return a;
}
public static void remove(List<String> list, String str) {
for(int i=0;i<list.size();)
{
if(list.get(i).equals(str))
{
list.remove(i);
i=0;
}
else
{
i++;
}
}
}
25.7-1 jmu-Java-01入门-开根号
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext()) {
double inputN = scanner.nextDouble();
double tmpN=0;
if (inputN<0) {
System.out.println(Double.NaN);
}else {
while(tmpN*tmpN<inputN&&(Math.abs(tmpN*tmpN-inputN)>0.0001)) {
tmpN+=0.0001;
}
System.out.printf("%.6f\n",tmpN);
}
}
scanner.close();
}
26.伪随机数
import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int k = sc.nextInt();
List<Integer> ss = new ArrayList<Integer>();
//Set<Integer> ss = new HashSet<Integer>();
Random rand = new Random(k);
for(int i = 0;i < n;i++)
{
ss.add(rand.nextInt(m));
if(i==n-1)
System.out.println(ss.get(i));
}
}
}
27. jmu-Java&Python-统计一段文字中的单词个数并按单词的字母顺序排序后输出
import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Set<String> words = new TreeSet<>();
Scanner sc = new Scanner(System.in);
while(true)
{
String ss = sc.next();
if(ss.equals("!!!!!"))
break;
else
words.add(ss);
}
System.out.println(words.size());
if(words.size() < 10)
{
for(String s : words)
System.out.println(s);
}
else
{
int count = 0;
for(String s : words)
{
if(count++ > 9)
break;
System.out.println(s);
}
}
sc.close();
}
}
28.设计一个Tiangle异常类
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double s1 = input.nextDouble();
double s2 = input.nextDouble();
double s3 = input.nextDouble();
try {
Triangle t = new Triangle(s1,s2,s3);
System.out.println(t);
}catch (IllegalTriangleException ex) {
System.out.println(ex.getMessage());
}
}
}
class IllegalTriangleException extends Exception{
private double side1;
private double side2;
private double side3;
public IllegalTriangleException(double side1,double side2 ,double side3) {
super("Invalid: "+side1+","+side2+","+side3);//message是父类成员变量,使用super向上传参!
this.side1=side1;
this.side2=side2;
this.side3=side3;
}
}
class Triangle{
private double side1;
private double side2;
private double side3;
public Triangle(double side1,double side2,double side3)
throws IllegalTriangleException{
if((side1+side2)>side3&(side1+side3)>side2&(side2+side3)>side1)
{this.side1=side1;this.side2=side2;this.side3=side3;}
else
throw new IllegalTriangleException(side1,side2,side3);
}
@Override
public String toString(){
return "Triangle ["+"side1="+this.side1+", side2="+this.side2+", side3="+this.side3+"]";
}
}
29. jmu-Java-07多线程-同步访问
public void deposit(int money) {
synchronized (this) {
balance += money;
notifyAll();
}
}
public void withdraw(int money) {
synchronized (this) {
while (balance < money) {
try {
wait();
} catch (InterruptedException e) {
}
}
balance -= money;
//notifyAll();
}
30.创建一个倒数计数线程
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Test t=new Test();
Thread th=new Thread(t);
th.start();
}
}
class Test implements Runnable {
public void run() {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
for(int i=n;i>=0;i--){
System.out.println(i);
try
{
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
31.试试多线程
public class Main {
public static void main(String [] args) {
A a = new A();
B b = new B();
C c = new C();
D d = new D();
a.start();
b.start();
c.start();
d.start();
try {
c.sleep(1000);
}
catch(Exception e1){
}
System.out.println(a.getNumber()+b.getNumber()+c.getNumber()+d.getNumber());
}
}
class A extends Thread{
private int sum;
@Override
public void run() {
for(int i=1;i<=25;i++) {
sum += i;
}
}
public int getNumber() {
return sum;
}
}
class B extends Thread{
private int sum;
@Override
public void run() {
for(int i=26;i<=50;i++) {
sum += i;
}
}
public int getNumber() {
return sum;
}
}
class C extends Thread{
private int sum;
@Override
public void run() {
for(int i=51;i<=75;i++) {
sum += i;
}
}
public int getNumber() {
return sum;
}
}
class D extends Thread{
private int sum;
@Override
public void run() {
for(int i=76;i<=100;i++) {
sum += i;
}
}
public int getNumber() {
return sum;
}
}