这样可以
成都创新互联-专业网站定制、快速模板网站建设、高性价比大英网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式大英网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖大英地区。费用合理售后完善,10多年实体公司更值得信赖。
public static void main(String[] args) {
String[] temps = {"A","B","C","D","E","F","G"};
for (int i = 1; i = temps.length; i++) {
for(int j = temps.length; j i; j--){
System.out.print(" ");
}
for (int j = 0; j i*2-1; j++) {
System.out.print(temps[i-1]);
}
System.out.println();
}
}
运行结果
A
BBB
CCCCC
DDDDDDD
EEEEEEEEE
FFFFFFFFFFF
GGGGGGGGGGGGG
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class ReadBook extends JFrame {
JTextArea jta;
JTextField jtf;
JButton jb;
public ReadBook() {
jta = new JTextArea();
jtf = new JTextField(30);
jtf.setText("文件保存路径如c:\\ab.txt");
jb = new JButton("保存文字");
JPanel jp = new JPanel();
jp.add(jtf);
jp.add(jb);
add(jta);
add(jp, BorderLayout.SOUTH);
setBounds(500, 100, 500, 380);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
jb.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//-------------核心代码---------
String path = jtf.getText();
File f = new File(path);
String txt = jta.getText().replaceAll("\n", "\r\n");
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(f));
bw.write(txt);//写入文件中
bw.close();
} catch (Exception e1) {
e1.printStackTrace();
}
//-------------核心代码---------
}
});
}
public static void main(String[] args) {
new ReadBook();
}
}
代码如下。。。。我测试过了。。。。希望能帮到你。。。
public class Test{
public static void main(String args[]){
int line = 4;//打印的行数
int data[][] = new int[line][line];
int index = 1;
int k = 0 ;
for(int i = 0;iline;i++){
for(int j = i; jline;j++)
data[j][j-k] = index++;
k++;
}
for(int i = 0; iline; i++){
for(int j = 0;j=i;j++)
System.out.print(data[i][j]+" ");
System.out.println();
}
}
}
运行结果:
1
5 2
8 6 3
10 9 7 4