黑客24小时在线接单网站

黑客技术,黑客教程,网络黑客,渗透测试,破解软件

java编程代码大全(java编程常用代码)

本文目录一览:

求java编程的代码

代码如下,望采纳

public class PrintPrime{

public static void main(String args[]){

    //设置一个计数变量count,用于统计一行当中已经输出数字的个数

int count = 0;

//写代码时人为判断200为非素数,如果不考虑题目的严格要求的话,可以写成200

for(int i = 100;i=200;i++){

    //判断数字是否为素数,若是,则count+1并输出数字

if(PrintPrime.IsPrime(i)){

count++;

System.out.print(i+" ");

}

//如果一行十个已经输出完毕,计数归零,换行

if(count==10){

count=0;

System.out.println();

}

}

}

//判断数字是否为素数

public static boolean IsPrime(int n){

    //如果小于等于三,则大于一即为素数

if (n = 3) {

return n  1;

}

        //从2循环到数字的开平方,算法优化

for(int i=2;i=Math.sqrt(n);i++){

if(n%i == 0)

return false;

}

return true;

}

}

java九九乘法表编程代码是什么?

package ch02;

public class TEST{

public static void main(String[] args) {

for (int i = 1; i =9; i++) {

for (int j = 1; j = i; j++) {

System.out.print(j+"*"+i+"="+(i*j)+" ");

}System.out.println();

}

}

}

测试结果 :

1*1=1

1*2=2 2*2=4

1*3=3 2*3=6 3*3=9

1*4=4 2*4=8 3*4=12 4*4=16

1*5=5 2*5=10 3*5=15 4*5=20 5*5=25

1*6=6 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36

1*7=7 2*7=14 3*7=21 4*7=28 5*7=35 6*7=42 7*7=49

1*8=8 2*8=16 3*8=24 4*8=32 5*8=40 6*8=48 7*8=56 8*8=64

1*9=9 2*9=18 3*9=27 4*9=36 5*9=45 6*9=54 7*9=63 8*9=72 9*9=81

实现思路:如果我们把九九乘法表中如“1*1=1”等式全部看作一个个整体的话,九九乘法表可看作一个直角三角形,实现直角三角形可用两个for循环嵌套来实现,那么我们最后输出应为System.out.print(变量1+"*"+变量2+"="+(变量1*变量2)+" ");

代码如下:

public class ChengDemo {

public static void main(String args[]){

for(int k = 1;k=9;k++){         //外循环用于控制行数      

for(int j = 1;j=k;j++){          

System.out.print(j+"*"+k+"="+(j*k)+"\t");     //"\t"为制表符

}  

System.out.println();  //换行

}

}

}

JAVA编程题求全部代码

class HW1 {

    public static void main(String[] args) {

        double[] test = new double[]{5.2, 1.0, 6.7, 3.4, 100.5, 55.5};

        BoundryValues boundryValues = getBoundryValues(test);

        System.out.println("Min Value = " + boundryValues.getMin());

        System.out.println("Max Value = " + boundryValues.getMax());

        System.out.println("Ave Value = " + boundryValues.getAve());

    }

    

    private static class BoundryValues {

        private double max;

        private double min;

        private double ave;

        

        public BoundryValues(){}

        

        public BoundryValues(double max, double min, double ave) {

            this.max = max;

            this.min = min;

            this.ave = ave;

        }

        

        public void setMax(double max) {

            this.max = max;

        }

        

        public double getMax() {

            return max;

        }

        

        public void setMin(double min) {

            this.min = min;

        }

        

        public double getMin() {

            return min;

        }

        

        public void setAve(double ave) {

            this.ave = ave;

        }

        

        public double getAve() {

            return ave;

        }

    }

    

    public static BoundryValues getBoundryValues(double[] doubles) {

        BoundryValues boundryValues = new BoundryValues();

        double[] results = sort(doubles);

        double total = 0.0;

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

            total += results[i];

        }

        boundryValues.setMin(results[0]);

        boundryValues.setMax(results[results.length - 1]);

        boundryValues.setAve(total/results.length);

        return boundryValues;

    }

    

    public static double[] sort(double[] doubles) {

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

            for (int j = 0; j  doubles.length - i - 1; j ++) {

                if (doubles[j]  doubles[j + 1]) {

                    double temp = doubles[j];

                    doubles[j] = doubles[j + 1];

                    doubles[j + 1] = temp;

                }

            }

        }

        return doubles;

    }

}

import java.util.*;

class HW2 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        double a, b, c;

        System.out.println("Enter a, b, c:");

        a = scanner.nextDouble();

        b = scanner.nextDouble();

        c = scanner.nextDouble();

        SetDouble sets = calculate(a, b, c);

        for (Double d : sets) {

            System.out.println("Values are: " + d + "\n");

        }

    }

    

    public static SetDouble calculate(double a, double b, double c) {

        SetDouble sets = new HashSetDouble();

        if (Math.pow(b, 2.0) - 4 * a * c  0) {

            System.err.println("No value");

        } else {

            sets.add((- b + Math.sqrt(Math.pow(b, 2.0) - 4 * a * c)) / 2.0 * a);

            sets.add((- b - Math.sqrt(Math.pow(b, 2.0) - 4 * a * c)) / 2.0 * a);

        }

        return sets;

    }

}

下午接着写

JAVA 编程,算法,详细在图里, 求代码、详细解答?

a、

有错误,因为类是公共的,文件名应该与类名同名,改成:A1Q4.java。

b、

因为main是静态方法,静态方法不能访问非静态成员。在3-4行的前面加上static就行了。

c、

不一样,是两个位于不同函数中的不同的局部变量。

d、

main是静态方法,不能访问实例方法restruct。

在restruct方法的前面加上static就行了。

e、

如果不在restruct方法的前面加static,可以先创建一个A1Q4的对象再访问restruct,在19行的前面加上:new A1Q4().就行了。

f、

输出:

The size of the array is 12

100, 2, 2, 100, 2, 2, 100, 2, 2, 100, 2, 2,

改好后的代码:

public class A1Q4 {

static Object element [] = new Object [12];

static int size = element.length;

static void restruct(Object a) {

int number = 2;

System.out.println("The size of the array is " + size);

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

if (i % 3 == 0)

element[i] = a;

else element[i] = new Integer(number);

}

}

public static void main(String[] args) {

int number = 100;

restruct(new Integer(number));

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

System.out.print(element[i] + ", ");

}

System.out.println();

}

}

或改成这样:

public class A1Q4 {

static Object element [] = new Object [12];

static int size = element.length;

void restruct(Object a) {

int number = 2;

System.out.println("The size of the array is " + size);

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

if (i % 3 == 0)

element[i] = a;

else element[i] = new Integer(number);

}

}

public static void main(String[] args) {

int number = 100;

new A1Q4().restruct(new Integer(number));

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

System.out.print(element[i] + ", ");

}

System.out.println();

}

}

java编程代码,要完整的代码,可以运行出来的。谢谢!

Course.java

public class Course {

    private String name;//课程名

    private String id; //编号

    private String selectId; //选修课编号

    public String getName() {

        return name;

    }

    public void setName(String name) {

        this.name = name;

    }

    public String getId() {

        return id;

    }

    public void setId(String id) {

        this.id = id;

    }

    public String getSelectId() {

        return selectId;

    }

    public void setSelectId(String selectId) {

        this.selectId = selectId;

    }

    

    

}

JAVA编程代码

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import java.io.*;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JTextField;

public class LoginFrame extends JFrame {

/**

*

*/

private static final long serialVersionUID = 2899557721654693611L;

final JTextField jt1 = new JTextField ();

final JTextField jt2 = new JTextField ();

public LoginFrame() {

this.setTitle("学生登陆");

this.setLayout(null);

this.setBounds(200, 200, 400, 300);

JButton jb1 = new JButton("登陆");

JButton jb2 = new JButton("退出");

jb1.setBounds(50, 230, 80, 20);

jb2.setBounds(270,230,80,20);

jt1.setBounds(170,80,100,20);

jt2.setBounds(170,170,100,20);

JLabel jl1 = new JLabel("用户名");

JLabel jl2 = new JLabel("密码");

jl1.setBounds(80, 80, 50, 20);

jl2.setBounds(80, 170, 50, 20);

add(jb1);

add(jb2);

add(jt1);

add(jt2);

add(jl1);

add(jl2);

this.setVisible(true);

this.addWindowListener(new WindowAdapter() {

@Override

public void windowClosing(WindowEvent e) {

// TODO Auto-generated method stub

setVisible(false);

System.exit(0);

}

});

jb1.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

new IntoTxt().intotex(jt1.getText(), jt2.getText());

}

});

jb2.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub

setVisible(false);

System.exit(0);

}

});

}

public static void main(String[] args) {

LoginFrame lf = new LoginFrame();

}

}

class IntoTxt {

public void intotex(String name,String password) {

BufferedWriter bw;

File file = new File("D:/write.txt");

if(!file.exists()) {

try {

file.createNewFile();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

try {

bw = new BufferedWriter(new FileWriter(file,true));

bw.newLine();

bw.write("用户名是 ");

bw.write(name);

bw.write(" 密码是 ");

bw.write(password);

bw.close();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

  • 评论列表:
  •  余安几钵
     发布于 2022-06-27 18:25:28  回复该评论
  • rn n  1; }        //从2循环到数字的开平方,算法优化 for(int i=2;i=Math.sqrt(n);i++){ if(n%i == 0) return false; }

发表评论:

«    2025年5月    »
1234
567891011
12131415161718
19202122232425
262728293031
文章归档
标签列表

Powered By

Copyright Your WebSite.Some Rights Reserved.