java的主函数在哪_打开一个别人的文件,一堆.java, 怎么知道main函数在哪里?

展开全部

向下边用java开发的一个计32313133353236313431303231363533e78988e69d8331333236356634数器的程序

它的文件名用计算器.java

用记事本打开代码如下:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.lang.*;

public class jsq {

JFrame f = new JFrame("计数器");

JMenuBar menubar1 = new JMenuBar();

JMenu menu1 = new JMenu("编辑");

JMenu menu2 = new JMenu("帮助");

JTextField text = new JTextField("", 10);

JButton bc = new JButton("清除");

JPanel p1 = new JPanel();

JPanel p2 = new JPanel();

FlowLayout fl = new FlowLayout(10, 10, 10);

JButton b1 = new JButton("1");

JButton b2 = new JButton("2");

JButton b3 = new JButton("3");

JButton bx = new JButton("*");

JButton b4 = new JButton("4");

JButton b5 = new JButton("5");

JButton b6 = new JButton("6");

JButton bch = new JButton("/");

JButton b7 = new JButton("7");

JButton b8 = new JButton("8");

JButton b9 = new JButton("9");

JButton bjj = new JButton("+");

JButton b0 = new JButton("0");

JButton bd = new JButton(".");

JButton bj = new JButton("-");

JButton bdy = new JButton("=");

public String shu1,shu2;

double add1;

char op;

private boolean hasdot=false ,hasfuhao=false; // 判断小数点

//boolean hasfuhao = false; // 判断是否有运算符号

private boolean panduan=false;

public jsq() {

}

public static void main(String args[]) {

jsq j1 = new jsq();

j1.go();

}

public void go() {

text.setHorizontalAlignment(JTextField.RIGHT);

menubar1.add(menu1);

menubar1.add(menu2);

f.setJMenuBar(menubar1);

f.getContentPane().add("North", p1);

f.getContentPane().add("Center", p2);

p1.add(text);

p1.add(bc);

p2.setLayout(fl);

p2.add(b1);

p2.add(b2);

p2.add(b3);

p2.add(bx);

p2.add(b4);

p2.add(b5);

p2.add(b6);

p2.add(bch);

p2.add(b7);

p2.add(b8);

p2.add(b9);

p2.add(bjj);

p2.add(b0);

p2.add(bd);

p2.add(bj);

p2.add(bdy);

bc.addActionListener(new JMenuHandler(10));

b1.addActionListener(new JMenuHandler(1));

b2.addActionListener(new JMenuHandler(2));

b3.addActionListener(new JMenuHandler(3));

b4.addActionListener(new JMenuHandler(4));

b5.addActionListener(new JMenuHandler(5));

b6.addActionListener(new JMenuHandler(6));

b7.addActionListener(new JMenuHandler(7));

b8.addActionListener(new JMenuHandler(8));

b9.addActionListener(new JMenuHandler(9));

b0.addActionListener(new JMenuHandler(0));

bd.addActionListener(new JMenuHandler2());

if (!panduan) { //第一次按这些按钮,就进行JMenuhandler1()监听

bx.addActionListener(new JMenuHandler1());

bch.addActionListener(new JMenuHandler1());

bjj.addActionListener(new JMenuHandler1());

bj.addActionListener(new JMenuHandler1());

}

else { //第二次按这些按钮,等同于等于的作用

bx.addActionListener(new JMenuHandler3());

bch.addActionListener(new JMenuHandler3());

bjj.addActionListener(new JMenuHandler3());

bj.addActionListener(new JMenuHandler3());

}

// bdy.addActionListener(new JMenuHandler3());

f.setSize(220, 280);

f.setVisible(true);

}

class JMenuHandler

implements ActionListener {

private int ch;

public JMenuHandler(int select) {

ch = select;

}

public void actionPerformed(ActionEvent e) {

String s = e.getActionCommand();//得到所按的按钮对应的值

switch (ch) {

case 10:

text.setText("");

hasdot = false;

hasfuhao = false;

panduan=false;

break;

case 0:

text.setText(text.getText() + s);

break;

case 1:

text.setText(text.getText() + s);

break;

case 2:

text.setText(text.getText() + s);

break;

case 3:

text.setText(text.getText() + s);

break;

case 4:

text.setText(text.getText() + s);

break;

case 5:

text.setText(text.getText() + s);

break;

case 6:

text.setText(text.getText() + s);

break;

case 7:

text.setText(text.getText() + s);

break;

case 8:

text.setText(text.getText() + s);

break;

case 9:

text.setText(text.getText() + s);

break;

}

}

}

class JMenuHandler1

implements ActionListener {//对运算符进行监听

public JMenuHandler1() {

}

public void actionPerformed(ActionEvent e) {

if (text.getText().equals("")) {

text.setText("");

}

else

if(!hasfuhao){

op = e.getActionCommand().charAt(0); //取得输入的运算符

if (!panduan) { //是第一次按此按钮

shu1 = text.getText(); //对第一次输入的数据进行记录

panduan = true;

text.setText("");

}

else{

shu2=text.getText();

System.out.println(shu2);

}

//System.out.println(shu1);

hasfuhao = true; //不能再输入运算符

hasdot = false; //可以再次输入小数点

}

}

}

class JMenuHandler2

implements ActionListener {//对小数点进行监听

//String ch1=text.getText();

public JMenuHandler2() {

}

public void actionPerformed(ActionEvent e) {

if(!text.getText().equals(""))

if (!hasdot) { //数中没有小数点

String str;

str = text.getText() + e.getActionCommand();

text.setText(str); //显示小数点

hasdot = true; //有小数点

}

}

}

class JMenuHandler3

implements ActionListener { //对等于号进行监听

public JMenuHandler3() {

double add1 = Double.parseDouble(shu1); //把shu1由string型转换成double型

System.out.println(add1);

}

double add1 = Double.parseDouble(shu1);

double shu2 = Double.parseDouble(text.getText());//类型转换,同上

public void actionPerformed(ActionEvent e) {

switch (op) {

case '+':

add1 = add1 + shu2;

break;

case '-':

add1 = add1 - shu2;

break;

case '*':

add1 = add1 * shu2;

break;

case '/':

add1 = add1 / shu2;

break;

}

if(panduan){

hasfuhao = false; //可以重新输入运算符

panduan = false;

}else{

op=e.getActionCommand().charAt(0);//新的运算符放到op中

hasfuhao=true;

}

hasdot = false; //可以重新输入小数点

text.setText(add1 + ""); //强制类型转换

}

}

}

在public static void main(String args[])出现main我们就可肯定它就main函数,一般出现main的是主函数。

2Q==

已赞过

已踩过<

你对这个回答的评价是?

评论

收起

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
下面是一个Java实现最大团问题的例子,包括一个主函数。该程序使用了回溯算法来求解最大团问题。 ```java import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class MaxClique { private int[][] graph; // 图的邻接矩阵 private int n; // 图中节点的个数 private List<Integer> result; // 最大团 public MaxClique(int[][] graph) { this.graph = graph; this.n = graph.length; this.result = new ArrayList<>(); } public List<Integer> getMaxClique() { boolean[] visited = new boolean[n]; // 记录节点是否被访问过 int[] clique = new int[n]; // 记录当前团的节点集合 int index = 0; // 记录当前团的节点个数 backtrack(visited, clique, index); return result; } private void backtrack(boolean[] visited, int[] clique, int index) { if (index == clique.length) { // 找到一个团 if (isClique(clique)) { if (clique.length > result.size()) { result = new ArrayList<>(Arrays.asList(Arrays.stream(clique).boxed().toArray(Integer[]::new))); } } return; } visited[index] = true; clique[index] = index; backtrack(visited, clique, index + 1); visited[index] = false; backtrack(visited, clique, index + 1); } private boolean isClique(int[] clique) { for (int i = 0; i < clique.length - 1; i++) { for (int j = i + 1; j < clique.length; j++) { if (graph[clique[i]][clique[j]] == 0) { return false; } } } return true; } public static void main(String[] args) { int[][] graph = { {0, 1, 1, 1}, {1, 0, 1, 0}, {1, 1, 0, 1}, {1, 0, 1, 0} }; MaxClique mc = new MaxClique(graph); List<Integer> maxClique = mc.getMaxClique(); System.out.println(maxClique); } } ``` 主函数中创建了一个邻接矩阵表示的图,然后调用 `getMaxClique` 方法来求解最大团。求解完成后,将最大团输出到控制台。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值