请为下面的java代码配上一个图形用户界面,谢谢
数组的全排列importjava.util.Scanner;publicclassmade{publicstaticvoidmain(String[]args){int[...
数组的全排列
import java.util.Scanner;
public class made {
public static void main(String[] args) {
int[] number;
number=new int[5];
Scanner input=new Scanner(System.in);
for(int i=0;i<5;i++){
number[i]=input.nextInt();
}
perm(number,0,number.length-1);
}
public static void perm(int[] number,int start,int end)
{
if(start==end)
{
for(int i=0;i<=end;i++)
{
System.out.print(number[i]);
}
System.out.println();
}
else{
for(int i=start;i<=end;i++)
{
int temp=number[start];
number[start]=number[i];
number[i]=temp;
perm(number,start+1,end);
temp=number[start];
number[start]=number[i];
number[i]=temp;
}
}
}
} 展开
import java.util.Scanner;
public class made {
public static void main(String[] args) {
int[] number;
number=new int[5];
Scanner input=new Scanner(System.in);
for(int i=0;i<5;i++){
number[i]=input.nextInt();
}
perm(number,0,number.length-1);
}
public static void perm(int[] number,int start,int end)
{
if(start==end)
{
for(int i=0;i<=end;i++)
{
System.out.print(number[i]);
}
System.out.println();
}
else{
for(int i=start;i<=end;i++)
{
int temp=number[start];
number[start]=number[i];
number[i]=temp;
perm(number,start+1,end);
temp=number[start];
number[start]=number[i];
number[i]=temp;
}
}
}
} 展开
展开全部
配上图形用户界面的Java程序如下:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class MadeGraph extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L;
JPanel jp1=new JPanel();
JPanel jp2=new JPanel();
JLabel jl1=new JLabel("请输入5个数:");
JLabel jl2=new JLabel("数组的全排列");
JTextField jtf=new JTextField(10);
JTextArea jta=new JTextArea(5,3);
JScrollPane jsp=new JScrollPane(jta);
JButton jb=new JButton("全排列");
MadeGraph(){
super("数组的全排列");
jb.addActionListener(this);
jp1.add(jl1);jp1.add(jtf);jp1.add(jb);
jp2.setLayout(null);
jl2.setBounds(55, 5, 280, 20);
jsp.setBounds(55, 25, 280, 280);
jp2.add(jl2);
jp2.add(jsp);
add(jp1,BorderLayout.NORTH);
add(jp2,BorderLayout.CENTER);
setSize(400, 400);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent ae) {
String[] num=jtf.getText().trim().split(" ");
int[] number=new int[num.length];
for(int i=0;i<num.length;i++){
number[i]=Integer.parseInt(num[i]);
}
perm(number,0,number.length-1);
}
public void perm(int[] number,int start,int end)
{
if(start==end)
{
for(int i=0;i<=end;i++)
{
jta.append(String.valueOf(number[i]));
}
jta.append("\n");
}
else{
for(int i=start;i<=end;i++)
{
int temp=number[start];
number[start]=number[i];
number[i]=temp;
perm(number,start+1,end);
temp=number[start];
number[start]=number[i];
number[i]=temp;
}
}
}
public static void main(String[] args) {
new MadeGraph();
}
}
运行结果:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询