java常用类编程题目

1、 输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 import java.util.*;

public class lianxi07 {

public static void main(String[] args) {

int digital = 0;

int character = 0;

int other = 0;

int blank = 0;

char[] ch = null;

Scanner sc = new Scanner(System.in);

String s = sc.nextLine();

ch = s.toCharArray();

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

if(ch >= '0' && ch <= '9') {

digital ++;

} else if((ch >= 'a' && ch <= 'z') || ch > 'A' && ch <= 'Z') {

character ++;

} else if(ch == ' ') {

blank ++;

} else {

other ++;

}

}

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

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

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

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

}

}

2、 两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定

比赛名单。有人向队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。

public class lianxi18 {

static char[] m = { 'a', 'b', 'c' };

static char[] n = { 'x', 'y', 'z' };

public static void main(String[] args) {

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

for (int j = 0; j < n.length; j++) {

if (m[i] == 'a' && n[j] == 'x') {

continue;

} else if (m[i] == 'a' && n[j] == 'y') {

continue;

} else if ((m[i] == 'c' && n[j] == 'x')

你可能喜欢

  • Java集合
  • JAVA编程题全集及答案
  • 期末考试答案
  • java基础知识总结
  • C语言程序设计
  • java编程思想
  • java编程入门
  • java编程规范

java常用类编程题目相关文档

最新文档

返回顶部