2道不会做的JAVA编程填空题.

来源:百度知道 编辑:UC知道 时间:2024/06/14 04:13:36
2道不会做的JAVA编程填空题,不知道谁能教教我?谢谢!!

1)下面的程序是求字符串的长度及每个位置上的字符。

public class Exe1{
public static void main(String args[]){
String str="abcdef";
int size=_____________________________;
System.out.println("字符串的长度为: "+size);
for (_________________________){
char c=___________________;
System.out.println("字符串中的第"+m+"个字符是: "+c);
}
}
}

2)本程序界面中有一个文本框、一个按钮和一个标签,用户在文本框中输入浮点数,当点
击按钮时,浮点数的平方根值在标签上得到显示

import java.awt.*;
import java.awt.event.*;
public class Exe2 ___________________________________{
Frame f=new Frame("计算平方根值");
FlowLayout flow=new FlowLayout( );
TextField a=new TextField(10);
Button b=new Button("计算");
Label c=new Label(" ");
public Exe

上面答案错误
应该为
int size=str.length();//此处L应该小写
for(int i=0;i<size;i++)
String c=str.substring(i,i+1);//此处S应该小写

第二题;
public class Exe2 implements ActionListener
y=Math.sqrt(x);
c.setText(""+y);
程序本身也有问题,少调用一个包
import javax.swing.*;

1、int size=str.Length();
for (int i=0;i<size;i++){
char c = str.subString(i,1);