当前位置:网站首页>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 .
边栏推荐
- 3. Oracle control file management
- 代码中的英语全部
- Game theory acwing 891 Nim games
- Vscode creates its own code template
- Knapsack problem acwing 9 Group knapsack problem
- Adg5412fbruz-rl7 applies dual power analog switch and multiplexer IC
- Winter messenger 2
- 求组合数 AcWing 888. 求组合数 IV
- 如何正确在CSDN问答进行提问
- Series of how MySQL works (VIII) 14 figures explain the atomicity of MySQL transactions and the principle of undo logging
猜你喜欢

Utf8 encoding
![[QT] QT multithreading development qthread](/img/7f/661cfb00317cd2c91fb9cc23c55a58.jpg)
[QT] QT multithreading development qthread

NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar

Day 2 document

What is socket? Basic introduction to socket

Bit of MySQL_ OR、BIT_ Count function

how to understand the “model independent.“

Game theory acwing 892 Steps Nim game

5. Oracle TABLESPACE

ADG5412FBRUZ-RL7应用 双电源模拟开关和多路复用器IC
随机推荐
Redis-01.初识Redis
RecyclerView的应用
Filter the numbers and pick out even numbers from several numbers
Vant weapp swippecell set multiple buttons
International Open Source firmware Foundation (osff) organization
[moviepy] unable to find a solution for exe
Day 2 document
Interval problem acwing 906 Interval grouping
Genesis builds a new generation of credit system
微信小程序路由再次跳轉不觸發onload
Bit of MySQL_ OR、BIT_ Count function
How to generate an image from text on fly at runtime
our solution
ollvm编译出现的问题纪录
C job interview - casting and comparing - C job interview - casting and comparing
区间问题 AcWing 906. 区间分组
[2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
博弈论 AcWing 894. 拆分-Nim游戏
Find the combination number acwing 889 01 sequence meeting conditions
La redirection de l'applet Wechat ne déclenche pas onload