当前位置:网站首页>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
- Dataframe (1): introduction and creation of dataframe
- [Chongqing Guangdong education] 1185t administrative leadership reference test of National Open University in autumn 2018
- Application of recyclerview
- RecyclerView的应用
- 1.手动创建Oracle数据库
- 2. Addition and management of Oracle data files
- [BMZCTF-pwn] ectf-2014 seddit
- Operator priority, one catch, no doubt
- Find the combination number acwing 888 Find the combination number IV
猜你喜欢
3.Oracle-控制文件的管理
Install opencv -- CONDA to establish a virtual environment and add the kernel of this environment in jupyter
论文阅读报告
高斯消元 AcWing 884. 高斯消元解异或线性方程组
代码中的英语全部
Record of problems in ollvm compilation
Vant weapp swippecell set multiple buttons
Speedtree01 generator properties
Vant weave swipecell sets multiple buttons
博弈论 AcWing 893. 集合-Nim游戏
随机推荐
时间很快,请多做有意义的事情
2048项目实现
LeetCode-54
[leetcode] day95 effective Sudoku & matrix zeroing
数据库Mysql全部
Package webapp or H5 pages into apps
Redis-02. Redis command
3.Oracle-控制文件的管理
Game theory acwing 892 Steps Nim game
Dataframe (1): introduction and creation of dataframe
Nested method, calculation attribute is not applicable, use methods
C job interview - casting and comparing - C job interview - casting and comparing
Ffmpeg build download (including old version)
将webApp或者H5页面打包成App
TypeScript入门
微信小程序路由再次跳轉不觸發onload
2022-5-第四周日报
Idea debug failed
Chapter 6 relational database theory
博弈论 AcWing 891. Nim游戏