JAVA案例26的简单介绍

博主:adminadmin 2022-12-14 01:00:06 72

今天给各位分享JAVA案例26的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

JAVA的小问题:将26个英文字母存放在一个list集合中,然后从集合中读出显示(原创,完整截图)

import java.util.ArrayList;

import java.util.List;

public class Test {

    public static void main(String[] args) {

        ListCharacter list = new ArrayListCharacter();//定义list

        for (int i = 65; i  91; i++) {//利用ascall循环得到A-Z的码

            list.add((char)i);//加入到list中

        }

        System.out.println(list.toString());//输入

    }

}

你也可以用list.add("A");添加26个字母然后输出

用java做的 将26个字母放入数组中( 谁能告诉我if(a[j]==0) 这个条件什么情况下a[j]=0)

这个程序写的真有点不知所谓,很是迷惑人啊,把26个字母放入数组中要这么麻烦吗?

不过也是实现了。

java和C#一样在定义数组的时候,如果没有赋初值,则为其自动赋值0

所以a[j]一开始都是0;

经过一轮循环赋值之后就是A~Z了。

用Java编写一个程序,按照倒序输出26个大写英文字母

public class PrintUpperChar {

public static void main(String[] args) {

for (char M = 'Z'; M = 'A'; M--) {

System.out.print(M);

}

}

}

java面向对象练习题,急求答案~ 【练习题】26.综合题 定义一个抽象的"Role"类,

1.

package com.huawei.test;

public abstract class Role

{

//姓名

private String name;

//性别

private String sex;

//年龄

private int age;

public Role()

{

}

public Role(String name,int age,String sex)

{

this.name = name;

this.age = age;

this.sex = sex;

}

public String getName()

{

return name;

}

public void setName(String name)

{

this.name = name;

}

public String getSex()

{

return sex;

}

public void setSex(String sex)

{

this.sex = sex;

}

public int getAge()

{

return age;

}

public void setAge(int age)

{

this.age = age;

}

public void play()

{

System.out.println("this is Role");

}

}

2.

package com.huawei.test;

public class Employee extends Role

{

//工资

private String salary;

//员工id

private String id;

public Employee()

{

super();

}

public Employee(String salary,String id)

{

super();

this.salary = salary;

this.id = id;

}

public void play()

{

System.out.println("this is Employee");

}

public final void sing()

{

System.out.println("Employee extends Role");

}

public String getSalary()

{

return salary;

}

public void setSalary(String salary)

{

this.salary = salary;

}

public String getId()

{

return id;

}

public void setId(String id)

{

this.id = id;

}

}

3.

package com.huawei.test;

public class Manager extends Employee

{

private String vehicle;

public Manager()

{

super();

}

public String getVehicle()

{

return vehicle;

}

public void setVehicle(String vehicle)

{

this.vehicle = vehicle;

}

}

4.

package com.huawei.test;

public class TestMethod

{

public static void main(String[] args)

{

Employee e = new Employee();

e.play();

e.sing();

Manager m = new Manager();

m.play();

m.sing();

}

}

java编程:用26个英文字母随即产生1000个英文大写字母,选出元音字母的个数以降序排列并输出相应的个数

public class Test {

public static void main(String[] args) {

String[] arr = new String[]{"a","b","c","d","e","f","g","h","i","j","k",

"l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};

ListString list=new ArrayListString();

Random rnd = new Random();

int countA = 0;

int countE = 0;

int countI = 0;

int countO = 0;

int countU = 0;

for (int i = 0; i 1000; i++) {

int index=rnd.nextInt(26);

String temp=arr[index];

if ("a".equals(temp) || "e".equals(temp) || "i".equals(temp)

|| "o".equals(temp) || "u".equals(temp)) {

list.add(temp) ;

}

if ("a".equals(temp)) {

countA++;

} else if ("e".equals(temp)) {

countE++;

} else if ("i".equals(temp)) {

countI++;

} else if ("o".equals(temp)) {

countO++;

} else if ("u".equals(temp)) {

countU++;

}

}

Collections.sort(list,new Comparator() {

public int compare(Object o1, Object o2) {

String s1 = (String)o1;

String s2 = (String)o2;

return s1.compareTo(s2)0 ? 1 :-1;

}

});

System.out.println(list);

System.out.println("a:"+countA+",e:"+countE+",i:"+countI+",o:"+countO+",u:"+countU);

}

}

关于JAVA案例26和的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-12-14,除非注明,否则均为首码项目网原创文章,转载请注明出处。