0
how do i concatenate two integers (a=5 b=6 System.out.print("sum"); the outout is 5 6
7 Antworten
+ 1
I think you can concatenate only strings, not the integer type.
+ 1
System.out.print(a + " " + b);
+ 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);
}}
0
so i shall declare string and concatenate it there?
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
}
}
0
thank you so much ^^ and thank you very much for repeating all of my codes tnx(leme geuss ctrl+c?)
0
you are welcome