本文目录一览:
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编程代码
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();
}
}
}