java考试 题

2024-12-12 01:10:04
推荐回答(4个)
回答1:

1.
public class suijishu {
public static void main(String[] args){
int sum=0;
int[] num=new int[10];
for(int i=0;i int temp=(int)(Math.random()*100);
num[i]=temp;
}
for(int i=0;i System.out.print(num[i]+" ");
sum+=num[i];
}
System.out.println();
System.out.println("数组元素之和为:"+sum);
}
}

2.
import java.util.*;

public class zifuchuan {
public static void main(String args[]){
String s1;
String s2;
int l1;
int l2;
Scanner s=new Scanner(System.in);
System.out.println("输入第一个字符串");
s1 = s.nextLine();
System.out.println("输入第二个字符串");
s2 = s.nextLine();
l1 = s1.length();
l2 = s2.length();
System.out.println("第一个字符串:"+s1);
System.out.println("第二个字符串:"+s2);
System.out.println("两串长度之差:"+Math.abs(l1-l2));
s1 = s1.toUpperCase();//转换为大写。
s2 = s2.toUpperCase();
//s1 = s1.toLowerCase();//转换为小写
//s2 = s2.toLowerCase();
System.out.println(s1+"\n"+s2);
s2 = s1+s2;//将两个串进行连接,结果存于第二个串中
System.out.println(s2);
}
}

3.
import java.awt.*;
import java.awt.event.*;

public class jisuanqiyemian extends Frame{
private TextField t_result;
private Panel p_main;
private Panel p_num;
private Panel p_oper;
private Panel p_show;
private Button b_num[];
private Button b_oper[];

public jisuanqiyemian(String title){
setTitle(title);
setLocation(500,300);
t_result=new TextField("0.0",23);
p_main=new Panel();
p_num=new Panel();
p_oper=new Panel();
p_show=new Panel();
p_main.setLayout(new BorderLayout());
p_num.setLayout(new GridLayout(4,3,1,1));
p_oper.setLayout(new GridLayout(4,2,1,1));

b_num=new Button[12];
for(int i=0;i<9;i++){
b_num[i]=new Button(new Integer(i+1).toString());
}
b_num[9]=new Button(" 0");
b_num[10]=new Button(" cls");
b_num[11]=new Button(" .");
for(int i=0;i<12;i++){
p_num.add(b_num[i]);
}

b_oper=new Button[8];
b_oper[0]=new Button(" +");
b_oper[1]=new Button(" -");
b_oper[2]=new Button(" *");
b_oper[3]=new Button(" /");
b_oper[4]=new Button(" pow");
b_oper[5]=new Button(" sqrt");
b_oper[6]=new Button(" +/-");
b_oper[7]=new Button(" =");
for(int i=0;i<8;i++){
p_oper.add(b_oper[i]);
}

t_result.setEditable(false);
p_show.add(t_result,BorderLayout.NORTH);
p_main.add(p_show,BorderLayout.NORTH);
p_main.add(p_num,BorderLayout.WEST);
p_main.add(p_oper,BorderLayout.EAST);
this.add(p_main,BorderLayout.CENTER);
setResizable(false);
pack();

this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
public static void main(String args[]){
jisuanqiyemian c=new jisuanqiyemian("计算器页面");
c.setVisible(true);
}
}

回答2:

别只知道要,要学会去学。
第一题
public class A
{
public static void main(String[] args)
{
int sum=0;
int[] num=new int[10];
for(int i=0;i {
int temp=(int)(Math.random()*100);
num[i]=temp;
}
for(int i=0;i {
System.out.print(num[i]+" ");
sum+=num[i];
}
System.out.println();
System.out.println("数组元素之和为:"+sum);
}
}

第二题
import java.util.*;
public class A
{
public static void main(String[] args)
{
String s1=null;
String s2=null;
int i1=0;
int i2=0;
Scanner s=new Scanner(System.in);
System.out.println("输入第一个字符串");
s1=s.nextLine();
System.out.println("输入第二个字符串");
s2=s.nextLine();
i1=s1.length();
i2=s2.length();
//输出两个串
System.out.println(s1+"\n"+s2);
//两个串长度之差
System.out.println("两串之差:"+(i1-i2));
//将小写字母转为大写字母
s1=s1.toUpperCase();
s2=s2.toUpperCase();
//将两个串进行连接,结果存于第二个串中
s2=s1+s2;
}
}

第三个就不写了.

回答3:

考试这些问题自己解决,,我想要分,你来解决....

经典

但是也是实话哈.
..........................
你这样的人.
...
..............鄙视

回答4:

这么简单的东西,自己弄吧。