解题思路:
注意事项:
参考代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
//输入n个数
int arr [] = new int[n];
String res = "";
for (int i=0;i<n;i++){
arr[i] = sc.nextInt();
//对arr[i]分 三种情况
if (arr[i]<0) {
//情况一:小于0
if (arr[i] == -1) {
//+/-1都要进行特殊处理
res = res + "-x^" + (n - i);
} else {
res = res + "-" + Math.abs(arr[i]) + "x^" + (n - i);
}
}
else if (arr[i]>0){
//情况二:大于0
if (arr[i] == 1) {
//+/-1都要进行特殊处理
res = res + "+x^" + (n - i);
} else {
res = res + "+" + arr[i] + "x^" + (n - i);
}
}
else{
//情况三:为0则直接跳过本轮循环
continue;
}
}
System.out.println(res.substring(1,res.length()-2));
sc.close();
/*
6
1 0 3 4 -2 2
*/
}
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:1243 |
C语言程序设计教程(第三版)课后习题8.3 (Java代码)浏览:1367 |
简单的a+b (C语言代码)浏览:759 |
C语言训练-排序问题<1> (C++代码)浏览:589 |
字符串的输入输出处理 (C语言代码)浏览:924 |
A+B for Input-Output Practice (V) (C语言代码)浏览:617 |
简单的a+b (C语言代码)浏览:596 |
三角形 (C语言代码)浏览:903 |
1013题解浏览:552 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:1067 |