java初期的敲代码题 java新手代码大全

一道Java编程题目,新手求详细代码

import java.io.BufferedReader;

成都创新互联是一家专业提供大武口企业网站建设,专注与成都做网站、成都网站建设、成都外贸网站建设HTML5、小程序制作等业务。10年已为大武口众多企业、政府机构等服务。创新互联专业的建站公司优惠进行中。

import java.io.IOException;

import java.io.InputStreamReader;

public class _1 {

/**

* @param args

* @throws IOException

*/

public static void main(String[] args) throws IOException {

// TODO Auto-generated method stub

String zifuchuan = new String("");

int hanzishu = 0;

int zimu = 0;

int kongge = 0;

int shuzi = 0;

int qita = 0;

System.out.print("请输入一行字符:");

BufferedReader stdin = new BufferedReader(new InputStreamReader(

System.in));

zifuchuan = stdin.readLine();

byte[] bytes = zifuchuan.getBytes();

for (int i = 0; i bytes.length; i++) {

if ((bytes[i] = 65 bytes[i] = 90)

|| (bytes[i] = 97 bytes[i] = 122))

zimu++;

else if (bytes[i] == 32)

kongge++;

else if (bytes[i] = 48 bytes[i] = 57)

shuzi++;

else if (bytes[i] 0)

hanzishu++;

else

qita++;

}

System.out.println("字符串所占字节个数为:" + bytes.length);

System.out.println("汉字个数为:" + hanzishu / 2);

System.out.println("英文字母个数为:" + zimu);

System.out.println("空格个数为:" + kongge);

System.out.println("数字个数为:" + shuzi);

System.out.println("其他字符个数为:" + qita);

}

}

JAVA敲代码..求教 作业题..

这个题目,考查你对数组结构、操作的了解

数组在内存中,是一组“长度固定的(创建以后就不可修改)、地址相邻的内存空间”,比如三个元素的数组

String[] array = {"1","2","3"};其内存结构

--------

| 1 |

--------

--------

| 2 |

--------

--------

| 3 |

--------

如果我要在第2个位置插入数据,则需要:

1、修改数组长度

2、将2、3向下移一个位置,空出一个给“ddd”

下面是实现代码

public static void main(String[] args) {

String[] array = { "1", "2", "3" };

array = insert(array, "ddd", 2);

for (int i = 0; i array.length; i++) {

System.out.print(array[i] + " ");

}

}

/**

* 在数组array的第index个位置,播放元素value,并返回该数组

*/

public static String[] insert(String[] array, String value, int index) {

//因为数组是“固定长度”,所以,必须要使用一个新的数组

String[] newArray = new String[array.length + 1];

int count = 0;

//将旧数组+插值得到新数组

for (int i = 0; i array.length; i++) {

if ((i + 1) == index) {

newArray[count++] = "ddd";

}

newArray[count++] = array[i];

}

return newArray;

}

Java入门编程题 求大佬帮忙解答一下 请附上代码和运行截图

public static void printMax(){

int[][] ay = {{22,91,0,5},{33,21},{19,-1,28,88}};

ListInteger list = new ArrayList();

for (int[] x:ay){

for (int y:x){

list.add(y);

}

}

System.out.println(Collections.max(list));

}

public static void main(String[] args) {

printMax();

}

JAVA初级编程题 求代码

public class Doctor {

private String name;

private int idNumber;

private String address;

public Doctor(String name, int idNumber, String address) {

super();

this.name = name;

this.idNumber = idNumber;

this.address = address;

}

public String getAddress() {

return address;

}

public void setAddress(String address) {

this.address = address;

}

public int getIdNumber() {

return idNumber;

}

public void setIdNumber(int idNumber) {

this.idNumber = idNumber;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String toString(){

return this.name+":"+this.idNumber+":"+this.address;

}

public static void main(String[] args) {

Doctor d1=new Doctor("cyq",10,"nanjin road shanghai");

NonSpecialist d2=new NonSpecialist("jr",11,"sichuan road shanghai");

Specialist d3=new Specialist("xyz",12,"beijin road shanghai");

d3.setSpecialty("medical ");

System.out.println(d1);

System.out.println(d2);

System.out.println(d3);

}

}

class NonSpecialist extends Doctor{

public NonSpecialist(String name, int idNumber, String address) {

super(name, idNumber, address);

}

}

class Specialist extends Doctor{

private String specialty;

public Specialist(String name, int idNumber, String address) {

super(name, idNumber, address);

}

public String getSpecialty() {

return specialty;

}

public void setSpecialty(String specialty) {

this.specialty = specialty;

}

@Override

public String toString() {

return super.toString()+":"+this.specialty;

}

}

好了,这样应该可以了


分享题目:java初期的敲代码题 java新手代码大全
地址分享:http://cdiso.cn/article/dosgpdh.html

其他资讯