当前位置:网站首页>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 .
边栏推荐
- [leetcode] day95 effective Sudoku & matrix zeroing
- How to correctly ask questions in CSDN Q & A
- 2048项目实现
- LSA Type Explanation - detailed explanation of lsa-2 (type II LSA network LSA) and lsa-3 (type III LSA network Summary LSA)
- International Open Source firmware Foundation (osff) organization
- LeetCode-54
- Modnet matting model reproduction
- 2048 project realization
- Time is fast, please do more meaningful things
- Dataframe (1): introduction and creation of dataframe
猜你喜欢
MPLS experiment
Adg5412fbruz-rl7 applies dual power analog switch and multiplexer IC
Financial risk control practice -- feature derivation based on time series
The “mode“ argument must be integer. Received an instance of Object
Interval problem acwing 906 Interval grouping
5. Oracle TABLESPACE
Install opencv -- CONDA to establish a virtual environment and add the kernel of this environment in jupyter
VLAN experiment
求组合数 AcWing 888. 求组合数 IV
博弈论 AcWing 893. 集合-Nim游戏
随机推荐
Simple selection sort of selection sort
Find the combination number acwing 887 Find combination number III
4.Oracle-重做日志文件管理
'mongoexport 'is not an internal or external command, nor is it a runnable program or batch file.
2. Addition and management of Oracle data files
P3265 [jloi2015] equipment purchase
在新线程中使用Handler
Series of how MySQL works (VIII) 14 figures explain the atomicity of MySQL transactions and the principle of undo logging
What is linting
博弈论 AcWing 891. Nim游戏
TCP's understanding of three handshakes and four waves
2048 project realization
[2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
LSA Type Explanation - detailed explanation of lsa-2 (type II LSA network LSA) and lsa-3 (type III LSA network Summary LSA)
H5 模块悬浮拖动效果
PR automatically moves forward after deleting clips
[wustctf2020] plain_ WP
Configuration method and configuration file of SolidWorks GB profile library
3.Oracle-控制文件的管理
Modnet matting model reproduction