本文目录一览:
- 1、java 怎么算乘法
- 2、JAVA 两个数相乘怎么写?
- 3、java 九九乘法表
- 4、java编程实现任意两个数组的乘法运算
- 5、java乘法运算
- 6、用Java代码实现输出乘法口诀表有几种方法?
java 怎么算乘法
package CMJqimo;
import java.util.Random;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class test {
static int trueresult = 0;
public static void main(String args[]) {
new test();
}
public test() {
JPanel jp = new JPanel();
JLabel jl = new JLabel();
JTextField jtf;
JFrame jf = new JFrame("Exam of Multiplication");
JButton jb = new JButton();
Container contentPane = jf.getContentPane();
contentPane.add(jp);
contentPane.setLayout(new BorderLayout());
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(300, 200);
jp.setLayout(new FlowLayout());
jp.setBackground(Color.GREEN);
jp.setSize(1000, 1000);
int num1 = random_number();
int num2 = random_number();
trueresult = num1 * num2;
JLabel jll = new JLabel(num1 + " x " + num2 + " =");
jp.add(jll);
jtf = new JTextField(5);
jp.add(jtf);
jb = new JButton("提交");
jp.add(jb);
jl = new JLabel(" ");
jp.add(jl);
contentPane.add(jp);
jf.setLocation(400, 200);
jf.setVisible(true);
jb.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int input = Integer.valueOf(jtf.getText());
String s = output_result(trueresult, input);
JOptionPane.showMessageDialog(jp, s);
int a = random_number();
int b = random_number();
trueresult = a * b;
jll.setText(a + " x " + b + " =");
jtf.setText("");
}
});
}
public static int read_input(String s) {
return Integer.parseInt(s);
};
public static int random_number() {
Random r = new Random();
int num = r.nextInt(10) + 1;
return num;
}
public String output_result(int trueresult, int input) {
Random r = new Random();
if (input == trueresult) {
String[] s = { "Very good", "Excellent", "Great job" };
return s[r.nextInt(3)];
} else {
return "No, please try again";
}
}
}
JAVA 两个数相乘怎么写?
public class Day25B {
public static void main(String[] args) {
baiint[] arr1=new int[5],arr2=new int[5],result=new int[5];
for (int i = 0; i result.length; i++) {
arr1[i]=(int)Math.round(Math.random()*40+10);
arr2[i]=(int)Math.round(Math.random()*40+10);
result[i]=arr1[i]*arr2[i];
}
System.out.println("索引\tarr1\tarr2\tresult");
for (int i = 0; i result.length; i++) {
System.out.println(i+"\t"+arr1[i]+" x "+arr2[i]+" =\t"+result[i]);
}
}
}
扩展资料:
javap 类文件反汇编器数据类型boolean 布尔型
byte 字节型
char 字符型
short 短整型
int 整形
long 长整形
float 单精度浮点型
double 双精度浮点型class 类null 空类型
interface 接口
java 九九乘法表
肯定的啊.第二个程序循环
for (int j=1;j==i;j++){
System.out.print(i+"*"+j+"="+(i*j)+"\t");
}
i=1时,j=1,好吧,出来了1*1=1
j=2时,i==j不成立了,所以j不++了.所以j永远是2了.永远不等于,所以不会打印了.
i=2,3,4,5,6,7,8,9时
j开始等于1,结果j永远不会等于i,所以j永远是1了,后面的也就不会执行,不会打印了
java编程实现任意两个数组的乘法运算
mport java.util.Scanner;
public class liujian {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
A num;
num=new A();
Scanner in = new Scanner(System.in);
System.out.print("输入第一个数:");
num.a = in.nextInt();
System.out.print("输入第二个数:");
num.b = in.nextInt();
System.out.println("两数相加的结果为:");
System.out.println(num.a+num.b);
System.out.println("两数相减的结果为:");
System.out.println(num.a-num.b);
System.out.println("两数相乘的结果为:");
System.out.println(num.a*num.b);
System.out.println("两数相除的结果为:");
System.out.println(num.a/num.b);
System.out.println("两数平方的结果为:");
System.out.println(num.a*num.b);
}
}
class A{
int a,b;
void jjcc(int s){
System.out.println(s);
}
}
java乘法运算
//早前写的,简易的!
import java.util.*;
public class TestSum {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
while(true){
init();
}
}
private static void init() {
System.out.println("请输入算数表达式如:1+1回车即可:");
String str = sc.nextLine();
if (!str.matches("[^a-zA-Z()^#$@!~]+")) {
System.out.println("输入错误重输:请输入算数表达式如:1+1回车即可:");
str = sc.nextLine();
}
int q = 0, h = 0, sum = 0;
char chs = ' ';
for (int i = 0; i str.length(); i++) {
chs = str.charAt(i);
if (chs == '+' || chs == '-' || chs == '*' || chs == '/') {
q = Integer.valueOf(str.substring(0, i));
h = Integer.valueOf(str.substring(i + 1, str.length()));
switch (chs) {
case '+':
sum = q + h;
break;
case '-':
sum = q - h;
break;
case '*':
sum = q * h;
break;
default:
sum = q / h;
break;
}
break;
}
}
System.out.println("结果="+sum+"\n继续下一轮:");
}
}
用Java代码实现输出乘法口诀表有几种方法?
用Java程序实现九九乘法口诀表,可以用for()循环的方法来实现,代码如下:
/**
*
* 用java实现九九乘法表
* for()循环
*
*/
public class Testjiujiuchengfabiao {
public static void main(String[] args) {
//外层循环控制行数,9行。
//内存循环控制列数、数量。
for(int i=1;i=9;i++)
{
for(int j=1;j=i;j++)
{
System.out.print(i+"*"+j +"=" +(i*j) +"\t");
}
//换行显示
System.out.println();
}
}
}