java程序输出四则运算口诀表代码正确版

正确例题
public class test {
public static void main(String[] args) {
String z=“aa,ab,ba,bb”;
String a=z.replaceAll(“a”, “0”);
System.out.println(a);
}
}

00,0b,b0,bb

[Process completed - press Enter]

正确例题
public class test {
public static void main(String[] args) {
String z=“aa,ab,ba,bb”;
String a=z.replace(“a”, “0”);
System.out.println(a);
}
}

00,0b,b0,bb

[Process completed - press Enter]

正确例题
public class test {
public static void main(String[] args) {
String z=“aa,ab,ba,bb”;
String a=z.replace(“a”, “0”).replace(“b”, “1”);
System.out.println(a);
}
}

00,01,10,11

[Process completed - press Enter]

正确例题,十进制转换为任意进制
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print(“请输入目标数的进制:”);
int jinzhi = scanner.nextInt();
System.out.print(“请输入要转换的数字:”);
int num = scanner.nextInt();
scanner.close();
String str = Integer.toString(num,jinzhi);
System.out.println(str);
}
}

正确例题
public class Test {
public static void main(String[] args) {
int z =2;
int i =7;
String a = Integer.toString(i,z);
System.out.println(a);
}
}

正确例题
public class Test {
public static void main(String[] args) {
int z =2;
int i =7;
int j =7;
String a = Integer.toString(i,z);
String b = Integer.toString(j,z);
System.out.println(a+“和”+b);
}
}

正确例题<2进制加法运算口诀表代码正确版>
public class Test {
public static void main(String[] args) {
int z =2;
int i =0;
int j =0;
int k ;

    for(i=0;i<9;i++){
            for(j=0;j<9;j++){
        k=i+j;

String a = Integer.toString(i,z);
    String b = Integer.toString(j,z);
    String c = Integer.toString(k,z);
    
System.out.println(a+"+"+b+"="+c);

}
}
}
}

0+0=0
0+1=1
0+10=10
0+11=11
0+100=100
0+101=101
0+110=110
0+111=111
0+1000=1000
1+0=1
1+1=10
1+10=11
1+11=100
1+100=101
1+101=110
1+110=111
1+111=1000
1+1000=1001
10+0=10
10+1=11
10+10=100
10+11=101
10+100=110
10+101=111
10+110=1000
10+111=1001
10+1000=1010
11+0=11
11+1=100
11+10=101
11+11=110
11+100=111
11+101=1000
11+110=1001
11+111=1010
11+1000=1011
100+0=100
100+1=101
100+10=110
100+11=111
100+100=1000
100+101=1001
100+110=1010
100+111=1011
100+1000=1100
101+0=101
101+1=110
101+10=111
101+11=1000
101+100=1001
101+101=1010
101+110=1011
101+111=1100
101+1000=1101
110+0=110
110+1=111
110+10=1000
110+11=1001
110+100=1010
110+101=1011
110+110=1100
110+111=1101
110+1000=1110
111+0=111
111+1=1000
111+10=1001
111+11=1010
111+100=1011
111+101=1100
111+110=1101
111+111=1110
111+1000=1111
1000+0=1000
1000+1=1001
1000+10=1010
1000+11=1011
1000+100=1100
1000+101=1101
1000+110=1110
1000+111=1111
1000+1000=10000

[Process completed - press Enter]

正确例题<2进制减法运算口诀表代码正确版>
public class Test {
public static void main(String[] args) {
int z =2;
int i =0;
int j =0;
int k ;

    for(i=0;i<9;i++){
            for(j=0;j<9;j++){
        k=i-j;

String a = Integer.toString(i,z);
    String b = Integer.toString(j,z);
    String c = Integer.toString(k,z);
    
System.out.println(a+"–"+b+"="+c);

}
}
}
}

正确例题<2进制乘法运算口诀表代码正确版>
public class Test {
public static void main(String[] args) {
int z =2;
int i =0;
int j =0;
int k ;

    for(i=0;i<9;i++){
            for(j=0;j<9;j++){
        k=i*j;

String a = Integer.toString(i,z);
    String b = Integer.toString(j,z);
    String c = Integer.toString(k,z);
    
System.out.println(a+"×"+b+"="+c);

}
}
}
}

猜你喜欢

转载自blog.csdn.net/qq_32257509/article/details/112135047