1.javaԴ?源码?????
2.java课程设计源代码(急!!源码!源码!源码整站程序 源码)
3.用JAVA编写的源码科学计算器源代码
javaԴ??????
代码如下:import java.util.Scanner;public class App {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int[] months = new int[];
for (int i = 0; i < months.length; i++) {
months[i] = scanner.nextInt();
}
for (int i = 0; i < months.length; i++) {
System.out.println((i + 1) + "月有" + months[i] + "天");
}
}
}
运行结果:
java课程设计源代码(急!!源码!源码!源码)
import java.awt.Color;
import java.awt.Font;
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.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;
public class game extends JFrame {
private JLabel label_2;
private int number;
private int sum;
final JLabel label = new JLabel();
final JLabel label_1 = new JLabel();
public static void main(String[] args) {
new game();
}
public game() {
super("点?!源码");
getContentPane().setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg0) {
onClick();
}
});
button.setText("出牌");
button.setBounds(,源码 , , );
getContentPane().add(button);
label.setBorder(new LineBorder(Color.black, 1, false));
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setFont(new Font("", Font.BOLD, ));
label.setText("背面");
label.setBounds(, , , );
getContentPane().add(label);
label_1.setText("你已经拥有的牌:");
label_1.setBounds(, , , );
getContentPane().add(label_1);
this.setBounds(, , , );
this.setVisible(true);
getContentPane().add(getLabel_2());
}
public int randNumber() {
try {
Thread.sleep();
} catch (InterruptedException e) {
e.printStackTrace();
}
return (int) (Math.random() * + 1);
}
public void onClick() {
number = this.randNumber();
this.sum += number;
label.setText("" + number);
String strTemp = this.label_1.getText();
strTemp += "" + number + " ";
label_1.setText(strTemp);
String temp = "合计:" + sum;
label_2.setText(temp);
isWin();
}
public void isWin() {
if (sum > ) {
JOptionPane.showMessageDialog(this, "你输了");
clear();
return;
} else if (sum == ) {
JOptionPane.showMessageDialog(this, "你赢了");
clear();
return;
} else {
int i = JOptionPane.showOptionDialog(this, "是否继续?", "提示",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, null, null);
if (i == JOptionPane.OK_OPTION) {
onClick();
} else
return;
}
}
private void clear() {
label_2.setText("合计:");
sum = 0;
number = 0;
label_1.setText("你已经拥有的牌:");
}
/
*** @return
*/
protected JLabel getLabel_2() {
if (label_2 == null) {
label_2 = new JLabel();
label_2.setText("合计:");
label_2.setBounds(, , , );
}
return label_2;
}
}
真好无聊中。。源码orm框架源码
用JAVA编写的源码科学计算器源代码
以下是一个简单的用Java编写的科学计算器的源代码示例:
java
import java.util.Scanner;
public class ScientificCalculator {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Welcome to the Scientific Calculator!");
System.out.println("Enter 'add', 'subtract', 'multiply', 'divide', 'sin', 'cos', 'tan', 'log', 'exp', 'sqrt', or 'quit' to exit.");
while (true) {
System.out.print("Enter operation (e.g., add 2 3): ");
String operation = scanner.nextLine();
if (operation.equalsIgnoreCase("quit")) {
break;
}
String[] parts = operation.split(" ");
double num1 = Double.parseDouble(parts[1]);
double num2 = Double.parseDouble(parts[2]);
switch (parts[0].toLowerCase()) {
case "add":
System.out.println(num1 + " + " + num2 + " = " + (num1 + num2));
break;
case "subtract":
System.out.println(num1 + " - " + num2 + " = " + (num1 - num2));
break;
case "multiply":
System.out.println(num1 + " * " + num2 + " = " + (num1 * num2));
break;
case "divide":
if (num2 != 0) {
System.out.println(num1 + " / " + num2 + " = " + (num1 / num2));
} else {
System.out.println("Error: Division by zero is not allowed.");
}
break;
case "sin":
System.out.println("sin(" + num1 + ") = " + Math.sin(Math.toRadians(num1)));
break;
case "cos":
System.out.println("cos(" + num1 + ") = " + Math.cos(Math.toRadians(num1)));
break;
case "tan":
System.out.println("tan(" + num1 + ") = " + Math.tan(Math.toRadians(num1)));
break;
case "log":
System.out.println("log(" + num1 + ") = " + Math.log(num1));
break;
case "exp":
System.out.println("exp(" + num1 + ") = " + Math.exp(num1));
break;
case "sqrt":
if (num1 >= 0) {
System.out.println("sqrt(" + num1 + ") = " + Math.sqrt(num1));
} else {
System.out.println("Error: Cannot calculate the square root of a negative number.");
}
break;
default:
System.out.println("Error: Invalid operation.");
break;
}
}
scanner.close();
System.out.println("Goodbye!");
}
}
这个科学计算器支持基本的四则运算(加、减、源码乘、源码除)以及一些科学运算(正弦、源码余弦、unity源码github正切、对数、指数和平方根)。用户可以通过输入相应的操作和两个数字来执行计算。例如,同城之恋源码输入“add 2 3”将计算2加3的结果。
代码首先导入了`Scanner`类,用于从用户处获取输入。然后,在`main`方法中,glide源码下载创建了一个`Scanner`对象,用于读取用户的输入。程序通过一个无限循环来持续接收用户的输入,直到用户输入“quit”为止。
在循环中,程序首先提示用户输入一个操作,然后读取用户的输入并将其分割为多个部分。接着,程序将第二个和第三个部分转换为`double`类型的数字,并根据第一个部分(即操作)执行相应的计算。
程序使用`switch`语句来根据用户输入的操作执行相应的计算。对于基本的四则运算,程序直接执行相应的计算并输出结果。对于科学运算,程序使用了Java的`Math`类中的相应方法。例如,对于正弦运算,程序使用了`Math.sin`方法,并将角度转换为弧度作为参数传递给它。
如果用户输入了无效的操作或无效