import java.util.Scanner;
public class Penjumlahan{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String nilai1;
String nilai2;
System.out.println("Masukkan nilai ke-1:"); nilai1=sc.next();
System.out.println("Masukkan nilai ke-2:"); nilai2=sc.next();
if(nilai1.length()<nilai2.length()){
int selisih=nilai2.length()-nilai1.length();
for(int nol=0;nol<selisih;nol++){
nilai1="0"+nilai2;
}
}
else if(nilai2.length()<nilai1.length()){
int selisih=nilai1.length()-nilai2.length();
for(int nol=0;nol<selisih;nol++){
nilai1="0"+nilai2;
}
}
String[] n1=new String[nilai1.length()];
String[] n2=new String[nilai2.length()];
for (int i=nilai1.length()-1;i>=0;i--){
n1[i]=nilai1.substring(i,i+1);
}
for (int i=nilai2.length()-1;i>=0;i--){
n2[i]=nilai2.substring(i,i+1);
}
String hasil="";
int simpan=0;
for(int i=nilai1.length()-1;i>=0;i--){
int temp = Integer.parseInt(n1[i]) + Integer.parseInt(n2[i]) + simpan;
if(temp >= 10){
temp = temp - 10;
hasil = String.valueOf(temp) + hasil;
simpan = 1;
}else{
hasil = String.valueOf(temp) + hasil;
simpan = 0;
}
}
if(simpan > 0){
hasil = String.valueOf(simpan) + hasil;
}
System.out.println("Hasil Penjumlahan : " + hasil);
}
}
public class Penjumlahan{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String nilai1;
String nilai2;
System.out.println("Masukkan nilai ke-1:"); nilai1=sc.next();
System.out.println("Masukkan nilai ke-2:"); nilai2=sc.next();
if(nilai1.length()<nilai2.length()){
int selisih=nilai2.length()-nilai1.length();
for(int nol=0;nol<selisih;nol++){
nilai1="0"+nilai2;
}
}
else if(nilai2.length()<nilai1.length()){
int selisih=nilai1.length()-nilai2.length();
for(int nol=0;nol<selisih;nol++){
nilai1="0"+nilai2;
}
}
String[] n1=new String[nilai1.length()];
String[] n2=new String[nilai2.length()];
for (int i=nilai1.length()-1;i>=0;i--){
n1[i]=nilai1.substring(i,i+1);
}
for (int i=nilai2.length()-1;i>=0;i--){
n2[i]=nilai2.substring(i,i+1);
}
String hasil="";
int simpan=0;
for(int i=nilai1.length()-1;i>=0;i--){
int temp = Integer.parseInt(n1[i]) + Integer.parseInt(n2[i]) + simpan;
if(temp >= 10){
temp = temp - 10;
hasil = String.valueOf(temp) + hasil;
simpan = 1;
}else{
hasil = String.valueOf(temp) + hasil;
simpan = 0;
}
}
if(simpan > 0){
hasil = String.valueOf(simpan) + hasil;
}
System.out.println("Hasil Penjumlahan : " + hasil);
}
}