(java编程) 输入一个数字,则输出其加法表 比如输入5,则输出 0+5=5 1+4=5 2+3=5 3+2=5 4+1=5 5+0=5
发布网友
发布时间:2022-04-30 03:43
我来回答
共3个回答
热心网友
时间:2023-10-10 02:53
package zuoye1;
import java.util.Scanner;
public class 累加 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner (System.in);
System.out.print("请输入一个值:");
int j = sc.nextInt();
System.out.println("根据这个值可以输出以下加法表:");
for(int i = 0;i<=j;i++) {
System.out.println(i+" + "+(j-i)+" = "+(j));
}
}
}
输出结果为:0+6=6
1+5=6
2+4=6
3+3=6
4+2=6
5+1=6
6+0=6
热心网友
时间:2023-10-10 02:53
public class Demo{
public static void main(String[] args){
InputStreamReader isr = new InputStreamReader(System.in);
BuffferedRreader br = new BufferedReader(isr);
int S = (int)br.readLine();
for(int i = 0; i <= S; i ++){
for(int j = S; j >= 0; j ++){
if(i + j == 5){
System.out.println(i + "+" + j = S);
}
}
}
}
}追问大哥,这个运行提示很多地方找不到符号啊,我是个新手,看的不大明白,怎么办,望提示下
追答import java.io.*;
public class Demo{
public static void main(String[] args){
int S = 0;
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
try{
S = Integer.parseInt(br.readLine());
}catch(Exception e){
System.out.println(e);
}
for(int i = 0; i = 0; j --){
if(i + j == S){
System.out.println(i + "+" + j + "=" + S);
}
}
}
}
}
热心网友
时间:2023-10-10 02:54
import java.util.Scanner;
public class Test {
public static void main(String[] args){
System.out.println("请输入一个数:");
Scanner in = new Scanner(System.in);
int n = in.nextInt();
for(int i = 0;i <= n;i++){
System.out.print(i+"+"+(n-i)+"="+n+" ");
}
}
}
运行结果:
请输入一个数:
5
0+5=5 1+4=5 2+3=5 3+2=5 4+1=5 5+0=5