「ac算法java」ac算法基础课

博主:adminadmin 2022-11-27 20:32:08 103

今天给各位分享ac算法java的知识,其中也会对ac算法基础课进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

如何用JAVA实现距离向量算法?急求!!!!!!

一个实例代表一个路由器(结点)。 npk )= S

实例之间利用UDP交换路由表。 wtw%)db

能够打印出邻居列表和输出路由表!

java构建一个数组,值从ab,ac,...az,ba,bb,...,bz,...到zz,输出指定数目比如输出87个

package TestHanLp;

import java.util.Scanner;

public class Test {

public static void main(String[] args) {

String [] str = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};

Scanner in=new Scanner(System.in);

System.out.println("请输入一个数:");

        int a=in.nextInt();

        int first = a / 26 ;

        int last = a % 26;

        

        System.out.println("前"+ a + "个值为:");

        

        for(int i = 0 ; i = first ; i ++ ) {

         for(int j = 0 ; j  26 ; j ++) {

         if(i + 1 = first) {

         System.out.print(str[i]+ str[j] + "   ");

         }else{

         if(j +1 = last) {

         System.out.print(str[i]+ str[j] + "   ");

         }

         }

         }

        }

}

}

这个可以不用数组的,不过既然你要求了,就加了一个

如何用java编程计算

你是问算法 还是带界面?

package Counter;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.*;

class pbl extends Frame

{

double x,y,a,b;

int z;

GridLayout gl1,gl2,gl3,gl4;

Button btn0,btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn10,btn11,btn12,btn13,btn14,btn15,btn16,btn17;

JTextField tf1;

StringBuffer str;

Panel p1,p2,p3,p4;

public pbl()

{

JFrame jf=new JFrame("计算器");

jf.setSize(180,280);

jf.setLocation(150,150);

gl1=new GridLayout(1,1,5,5);

gl2=new GridLayout(5,3,5,5);

gl3=new GridLayout(3,1,5,5);

gl4=new GridLayout(1,1,5,5);

p1=new Panel();

p1.setLayout(gl1);

tf1=new JTextField("0");

tf1.setHorizontalAlignment(JTextField.RIGHT);

p1.add(tf1);

p1.setBounds(10, 20,153, 30);

tf1.setEditable(false);

str=new StringBuffer();

btn1=new Button("1");

btn1.setForeground(Color.BLUE);

btn1.addActionListener(new ac());

btn2=new Button("2");

btn2.setForeground(Color.BLUE);

btn2.addActionListener(new ac());

btn3=new Button("3");

btn3.setForeground(Color.BLUE);

btn3.addActionListener(new ac());

btn4=new Button("4");

btn4.setForeground(Color.BLUE);

btn4.addActionListener(new ac());

btn5=new Button("5");

btn5.setForeground(Color.BLUE);

btn5.addActionListener(new ac());

btn6=new Button("6");

btn6.setForeground(Color.BLUE);

btn6.addActionListener(new ac());

btn7=new Button("7");

btn7.setForeground(Color.BLUE);

btn7.addActionListener(new ac());

btn8=new Button("8");

btn8.setForeground(Color.BLUE);

btn8.addActionListener(new ac());

btn9=new Button("9");

btn9.setForeground(Color.BLUE);

btn9.addActionListener(new ac());

btn0=new Button("0");

btn0.setForeground(Color.BLUE);

btn0.addActionListener(new ac());

btn10=new Button("+");

btn10.setForeground(Color.RED);

btn10.addActionListener(new ac());

btn11=new Button("-");

btn11.setForeground(Color.RED);

btn11.addActionListener(new ac());

btn12=new Button("*");

btn12.setForeground(Color.red);

btn12.addActionListener(new ac());

btn13=new Button("/");

btn13.setForeground(Color.RED);

btn13.addActionListener(new ac());

btn14=new Button(".");

btn14.setForeground(Color.RED);

btn14.addActionListener(new ac());

btn15=new Button("+/-");

btn15.setForeground(Color.RED);

btn15.addActionListener(new ac());

btn16=new Button("CE");

btn16.setForeground(Color.RED);

btn16.addActionListener(new ac());

btn17=new Button("=");

btn17.setForeground(Color.RED);

btn17.addActionListener(new ac());

p2=new Panel();

p2.setLayout(gl2);

p2.add(btn16);

p2.add(btn13);

p2.add(btn12);

p2.add(btn1);

p2.add(btn2);

p2.add(btn3);

p2.add(btn4);

p2.add(btn5);

p2.add(btn6);

p2.add(btn7);

p2.add(btn8);

p2.add(btn9);

p2.add(btn0);

p2.add(btn14);

p2.add(btn15);

p2.setBounds(10, 75, 120, 150);

p3=new Panel();

p3.setLayout(gl3);

p3.add(btn10);

p3.add(btn17);

p3.setBounds(133,105,30,182);

p4=new Panel();

p4.setLayout(gl4);

p4.add(btn11);

p4.setBounds(133, 75, 30, 26);

jf.setLayout(null);

jf.setResizable(false);

jf.add(p1);

jf.add(p2);

jf.add(p3);

jf.add(p4);

jf.setVisible(true);

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

class ac implements ActionListener

{

public void actionPerformed(ActionEvent ce)

{

if(ce.getSource()==btn16)

{

tf1.setText("0");//ce

str.setLength(0);

}

else if(ce.getSource()==btn15)//(+/-)

{

a=Double.parseDouble(tf1.getText());

//a*=-1;

tf1.setText(""+(-a));

}

else if(ce.getSource()==btn14)//(.)

{

if(tf1.getText().trim().indexOf(".")!=-1)

{

}

else if(tf1.getText().trim().equals("0"))

{

tf1.setText("0"+str.append(ce.getActionCommand()).toString());

}

else

{

tf1.setText(str.append(ce.getActionCommand()).toString());

}

}

else if(ce.getSource()==btn10)//(+)

{

x=Double.parseDouble(tf1.getText().trim());

str.setLength(0);

y=0;

z=1;

}

else if(ce.getSource()==btn11)//(-)

{

x=Double.parseDouble(tf1.getText().trim());

str.setLength(0);

y=0;

z=2;

}

else if(ce.getSource()==btn12)//(*)

{

x=Double.parseDouble(tf1.getText().trim());

str.setLength(0);

y=0;

z=3;

}

else if(ce.getSource()==btn13)//(/)

{

x=Double.parseDouble(tf1.getText().trim());

str.setLength(0);

y=0;

z=4;

}

else if(ce.getSource()==btn17)//(=)

{

str.setLength(0);

y=Double.parseDouble(tf1.getText().trim());

switch (z)

{

case 1: tf1.setText(""+(x+y)) ;break;

case 2: tf1.setText(""+(x-y)) ;break;

case 3: tf1.setText(""+(x*y)) ;break;

case 4: tf1.setText(""+(x/y)) ;break;

}

z=0;

}

else

{

tf1.setText(str.append(ce.getActionCommand()).toString());

}

}

}

public static void main(String[] args)

{

new pbl();

}

}

java排列组合的算法 譬如我有(A,B,C,D),我想输出的结果是

我觉得可以看成数字的排列如 1 2 3 4分别代表A B C D

就是将1 2 3 4排列

四位的就是1234

三位的就是从这四个数字中取出三个数字,得到的三位数是最小的,如:

取 1 2 3 可以得到123 213 321 132等等 其中123是最小的

两为数字的跟三位数字的一样

java实现如下:已知平面内三点,其中一个为顶点,求顶点与其他两点构成直线的夹角。

//trangle 函数里面是三点坐标。其中A为直角

public static void trangle(double a_x,double a_y,double b_x,double b_y,double c_x,double c_y){

//Math.sqrt(x)表示开根号。Math.pow(x,n)表示x的n次方。

double ab = Math.sqrt(Math.pow(a_x-b_x, 2) + Math.pow(a_y - b_y, 2));//直线ab

double ac = Math.sqrt(Math.pow(a_x-c_x, 2) + Math.pow(a_y - c_y, 2));//直线bc

//求角B,C度数。Math.PI表示π;Math.atan2(x, y)表示arctant(x/y),在Java中是弧线长度,因此要将长度转换为度数。

double B = Math.atan2(ac, ab)*180/Math.PI;

double C = Math.atan2(ab, ac)*180/Math.PI;

System.out.println("B:"+B+"°\nC:"+C+"°");

}

java实现,从a,b,c,d,e,f,g,h,i...aa,ab,ac,...az,ba,bb,.,bz,..到zz,输出指定数目比如输出前87个

String az = "abcdefghijklmnopqrstuvwxyz";

ArrayListString al = new ArrayListString();

for(int j=0; jaz.length(); j++) al.add(az.substring(j,j+1));

for(int i=0; iaz.length(); i++){

for(int j=0; jaz.length(); j++) al.add(az.substring(i,i+1)+az.substring(j,j+1));

}

for(int j=0; j87; j++) System.out.println(al.get(j));

运行结果:

a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ad ae af ag ah ai aj ak al am an ao ap aq ar as at au av aw ax ay az ba bb bc bd be bf bg bh bi bj bk bl bm bn bo bp bq br bs bt bu bv bw bx by bz ca cb cc cd ce cf cg ch ci

ac算法java的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于ac算法基础课、ac算法java的信息别忘了在本站进行查找喔。

The End

发布于:2022-11-27,除非注明,否则均为首码项目网原创文章,转载请注明出处。