how do i concatenate two integers (a=5 b=6 System.out.print("sum"); the outout is 5 6 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how do i concatenate two integers (a=5 b=6 System.out.print("sum"); the outout is 5 6

24th Aug 2016, 12:52 PM
thomas
7 Answers
+ 1
I think you can concatenate only strings, not the integer type.
24th Aug 2016, 12:56 PM
Karan Mahajan
Karan Mahajan - avatar
+ 1
System.out.print(a + " " + b);
24th Aug 2016, 1:38 PM
Tiger
Tiger - avatar
+ 1
import java.util.Scanner; class Test{ public static void main(String[]args){ Scanner num=new Scanner(System.in); int from,to,odd=0,even=0,num3=0; String num2=""; String num1=""; System.out.print("from:"); from=num.nextInt(); System.out.print("to:"); to=num.nextInt(); num3=to+1; if(num3>=from){ while(to>=from){ if(from%2==0){ even++; num2+=from+" "; }else{ odd++; num1+=from+" "; } from++; } } else{ while(from>=to){ if(from%2==0){ even++; num2+=from+" "; } else{ odd++; num1+=from+" "; } from--; } } System.out.println(); System.out.println("odd number:("+odd+")"+num1); System.out.println("even number:("+even+")"+num2); }}
24th Aug 2016, 2:27 PM
Tiger
Tiger - avatar
0
so i shall declare string and concatenate it there?
24th Aug 2016, 1:00 PM
thomas
0
here is my codes Import java.util.Scanner; public Static void main(String[]args){ Scanner num=new Scanner(System.in); int from,to,odd=0,even=0,num1,num2,num3; System.out.print("from:"); from=num.nextInt(); System.out.print("to:"); to=num.nextInt(); num3=to+1; if(num3>=from){ while(to>=from){ if(from%2==0){ even++; num2=from+" "; - error } else{ odd++; num1=from+" "; - error } from++; } System.out.print("odd number:("+odd+")"+num1); - error System.out.print(" even number:("+even+")"+num2); - error } else if(from>=num3){ while(from>=to){ if(from%2==){ even++; num2=from+" "; - error } else{ odd++ num1=from+" "; - error } from--; } System.out.print("odd number:("+odd+")"+num1); - error System.out.print(" even number:("+even+")"+num2); - error } }
24th Aug 2016, 1:41 PM
thomas
0
thank you so much ^^ and thank you very much for repeating all of my codes tnx(leme geuss ctrl+c?)
24th Aug 2016, 2:30 PM
thomas
0
you are welcome
24th Aug 2016, 4:29 PM
Tiger
Tiger - avatar