当前位置:网站首页>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 .
边栏推荐
- Single chip computer engineering experience - layered idea
- Relevant information of National Natural Science Foundation of China
- Suppose a bank's ATM machine, which allows users to deposit and withdraw money. Now there is 200 yuan in an account, and both user a and user B have the right to deposit and withdraw money from this a
- Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
- MPLS experiment
- 论文阅读报告
- 2048项目实现
- Paper reading report
- [2021]GIRAFFE: Representing Scenes as Compositional Generative Neural Feature Fields
- 20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore
猜你喜欢
随机推荐
C Primer Plus Chapter 15 (bit operation)
our solution
vsCode创建自己的代码模板
The route of wechat applet jumps again without triggering onload
Utf8 encoding
How to understand the definition of sequence limit?
Client use of Argo CD installation
H5 module suspension drag effect
5.Oracle-表空间
Package webapp or H5 pages into apps
2022-5-第四周日报
Record of problems in ollvm compilation
Suppose a bank's ATM machine, which allows users to deposit and withdraw money. Now there is 200 yuan in an account, and both user a and user B have the right to deposit and withdraw money from this a
how to understand the “model independent.“
Modnet matting model reproduction
Winter messenger 2
[learning] database: several cases of index failure
H5 embedded app adapts to dark mode
4. Object mapping Mapster
VLAN experiment









