重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

java基础字符串代码题,java编程基础题

java面向对象基础题目(字符串)

选B,change函数的入口参数为str则只修改传入参数,若在函数体内使用“this.str=str”则发生互换,第二个直接修改了引用值,导致发生改变。

创新互联建站专注于安宁企业网站建设,响应式网站设计,商城系统网站开发。安宁网站建设公司,为安宁等地区提供建站服务。全流程按需网站开发,专业设计,全程项目跟踪,创新互联建站专业和态度为您提供的服务

JAVA 字符串题,求快速完整作答!!急

public static void main(String[] args) { Scanner s=new Scanner(System.in); // process(s); process2(s); } public static void process(Scanner s) { String str; int[] count=new int[4]; int[] lowCount=new int[4]; int[] highCount=new int[4]; String[] lowStr=new String[4]; String[] highStr=new String[4]; while(true) { str=s.nextLine();// 这里用回车确认输入每一个字符串 if(str.equals("end")) { break; } char[] cc=str.toCharArray(); int[] tempCount=new int[4]; for(char c: cc) { switch(c) { case 'A': count[0]++; tempCount[0]++; break; case 'C': count[1]++; tempCount[1]++; break; case 'G': count[2]++; tempCount[2]++; break; case 'T': count[3]++; tempCount[3]++; break; default: System.out.println("Error!"); } } for(int i=0; i 4; i++) { if(lowCount[i] == 0) { lowCount[i]=tempCount[i]; lowStr[i]=str; } else if(lowCount[i] tempCount[i] tempCount[i] != 0) { lowCount[i]=tempCount[i]; lowStr[i]=str; } if(highCount[i] == 0) { highCount[i]=tempCount[i]; highStr[i]=str; } else if(highCount[i] tempCount[i]) { highCount[i]=tempCount[i]; highStr[i]=str; } } } System.out.println("A count: " + count[0]); System.out.println("C count: " + count[1]); System.out.println("G count: " + count[2]); System.out.println("T count: " + count[3]); System.out.println("Low A count: " + lowStr[0]); System.out.println("High A count: " + highStr[0]); System.out.println("Low C count: " + lowStr[1]); System.out.println("High C count: " + highStr[1]); System.out.println("Low G count: " + lowStr[2]); System.out.println("High G count: " + highStr[2]); System.out.println("Low T count: " + lowStr[3]); System.out.println("High T count: " + highStr[3]); } public static void process2(Scanner s) { int n=Integer.parseInt(s.nextLine()); String[] strs=new String[n]; int[] count=new int[n]; for(int i=0; i n; i++) { strs[i]=s.nextLine(); } while(true) { String temp=s.nextLine();// 这里用回车确认输入每一个字符串 if(temp.equals("end")) { break; } for(int i=0; i n; i++) { for(int j=0; j temp.length()-strs[i].length()+1; j++) { String temp2=temp.substring(j,j+strs[i].length()); if(temp2.equals(strs[i])) { count[i]++; } } } } for(int i=0; i n; i++) { System.out.println("Partten " + strs[i] + " count: " + count[i]); } }

java字符串替换题?

public class Test {

public static void main(String[] args) {

String input = "aaa果4金5a";

StringBuffer sb = new StringBuffer();

char[] c = input.toCharArray();

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

if (c[i] = '0' c[i] = '9') {

int tmp = Integer.valueOf(String.valueOf(c[i]));

for (int j = 0; j tmp; j++) {

sb.append(c[i + 1]);

}

i++;

} else {

sb.append(c[i]);

}

}

System.out.println(sb.toString());

}

}


文章题目:java基础字符串代码题,java编程基础题
地址分享:http://cqcxhl.com/article/phjsje.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP