当前位置:网站首页>Sum of two numbers, the numbers in the array are converted to decimal, added, and output inversely
Sum of two numbers, the numbers in the array are converted to decimal, added, and output inversely
2022-07-05 06:36:00 【Said it was all】
public class Sum of two numbers {
public static void main(String[] args) {
Sum of two numbers t=new Sum of two numbers ();
System.out.println(" Enter the first array , Whitespace separated ");
int arr1[]=t.arr();
int sum1=0;
int sum2=0;
for(int i=0;i<arr1.length;i++){
sum1 = sum1+(int) (arr1[i]*(Math.pow(10,arr1.length-(i+1))));
}
System.out.println(" Enter the second array , Whitespace separated ");
int arr2[]=t.arr();
for ( int i=0;i<arr2.length;i++){
sum2 = sum2+(int) (arr2[i]*(Math.pow(10,arr1.length-(i+1))));
}
int sum=sum1+sum2;
String ssum=String.valueOf(sum);
String sumarry[] = ssum.split("");
for(int i=0;i<sumarry.length;i++){
if(i==sumarry.length-(i+1)) break; // Odd critical condition
if(i>sumarry.length-(i+1)) break; // Even critical condition
String c=sumarry[sumarry.length-(i+1)];
sumarry[sumarry.length-(i+1)] =sumarry[i];
sumarry[i]=c;
}
for (String a:sumarry){
System.out.print(a);
}
}
public int[] arr (){
Scanner sc = new Scanner(System.in);
String inputString = sc.nextLine();
String stringArray[] = inputString.split(" ");
int intarr[]=new int[stringArray.length];
for (int i=0;i<stringArray.length;i++){
intarr[i]=Integer.parseInt(stringArray[i]);
}
return intarr;
}
}
Example :
Similar to the second question of Li Kou , But there is no linked list here .
边栏推荐
- SQL三种连接:内连接、外连接、交叉连接
- [Chongqing Guangdong education] 1185t administrative leadership reference test of National Open University in autumn 2018
- Redis-01. First meet redis
- How to make water ripple effect? This wave of water ripple effect pulls full of retro feeling
- 如何正确在CSDN问答进行提问
- 微信小程序路由再次跳轉不觸發onload
- C Primer Plus Chapter 15 (bit operation)
- 3.Oracle-控制文件的管理
- Sum of three terms (construction)
- 求组合数 AcWing 887. 求组合数 III
猜你喜欢
达梦数据库全部
1.手动创建Oracle数据库
背包问题 AcWing 9. 分组背包问题
Interval problem acwing 906 Interval grouping
2021apmcm post game Summary - edge detection
3. Oracle control file management
How to make water ripple effect? This wave of water ripple effect pulls full of retro feeling
3.Oracle-控制文件的管理
Design specification for mobile folding screen
[moviepy] unable to find a solution for exe
随机推荐
P2575 master fight
【LeetCode】Easy | 20. Valid parentheses
5. Oracle TABLESPACE
FFmpeg build下载(包含old version)
Ffmpeg build download (including old version)
Game theory acwing 891 Nim games
3. Oracle control file management
PR automatically moves forward after deleting clips
Alibaba's new member "Lingyang" officially appeared, led by Peng Xinyu, Alibaba's vice president, and assembled a number of core department technical teams
2048 project realization
2. Addition and management of Oracle data files
[BMZCTF-pwn] ectf-2014 seddit
How to understand the definition of sequence limit?
时间很快,请多做有意义的事情
MQClientException: No route info of this topic: type_ topic
MySQL (UDF authorization)
1.手动创建Oracle数据库
Vant weapp swippecell set multiple buttons
4.Oracle-重做日志文件管理
How to set the drop-down arrow in the spinner- How to set dropdown arrow in spinner?