这4道JAVA题目怎么做
4个回答
推荐于2016-02-16 · 知道合伙人数码行家
关注
展开全部
//第一题:
public class Demo001{
public static void main(String[] args) throws Exception {
int[] c = {1,2,3,4,5,6};
StringBuilder sb = new StringBuilder();
for(int i = 0; i < c.length; i++){
if(i==0){
sb.append("{"+c[i]+",");
}else if(i < (c.length/2)){
if(i == c.length/2-1){
sb.append(c[i]+"}");
}else{
sb.append(c[i]+",");
}
}else{
if(i==c.length/2){
sb.append(",{"+c[i]+",");
}else if(i==c.length-1){
sb.append(c[i]+"}");
}else{
sb.append(c[i]+",");
}
}
}
System.out.println(sb.toString());
}
}
//第二道题,不是很明白。
//第三道题:
int[] arr = {1,2,3,4,5,6};
//删除下标2的
arr[2] = 0;
//删除数组
arr = null;
展开全部
我看到楼上有人回答了两道题,那么我来回答一下中间这道题吧。
String[] name = {"小明","小花","小王","小李","张三","李四","王五","赵六","钱七","宋珊"};
Random r = new Random();
String[] selected = new String[3];
for(int i = 0;i<3;i++){
int index = R.nextInt(10);
if("null".equals(name[index])){
i--;
continue;
}
selected[i] = name[index];
name[index] = "null";
System.out.println("第"+(i+1)+"位是:"+selecten[i]);
}
String[] name = {"小明","小花","小王","小李","张三","李四","王五","赵六","钱七","宋珊"};
Random r = new Random();
String[] selected = new String[3];
for(int i = 0;i<3;i++){
int index = R.nextInt(10);
if("null".equals(name[index])){
i--;
continue;
}
selected[i] = name[index];
name[index] = "null";
System.out.println("第"+(i+1)+"位是:"+selecten[i]);
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是我的问题吗 我只看到了3道题
追问
那你能帮我下?
追答
有人在做了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
第四题
public class test {
public static void main(String[] args) {
new test().fun();
}
public void fun(){
int c[] ={1,2,3,4,5,6};
int[] a = new int[c.length/2];
int[] b = new int[c.length/2];
int t=0;
for(int i=0;i<c.length/2;i++){
a[t]=c[i];
t++;
}
t=0;
for(int i =c.length/2;i<c.length;i++){
b[t]=c[i];
t++;
}
for(int i=0;i<a.length;i++){
System.out.print(a[i]);
}
for(int i=0;i<b.length;i++){
System.out.print(b[i]);
}
}
}
public class test {
public static void main(String[] args) {
new test().fun();
}
public void fun(){
int c[] ={1,2,3,4,5,6};
int[] a = new int[c.length/2];
int[] b = new int[c.length/2];
int t=0;
for(int i=0;i<c.length/2;i++){
a[t]=c[i];
t++;
}
t=0;
for(int i =c.length/2;i<c.length;i++){
b[t]=c[i];
t++;
}
for(int i=0;i<a.length;i++){
System.out.print(a[i]);
}
for(int i=0;i<b.length;i++){
System.out.print(b[i]);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |