変数に数値を保存する必要があります。2つの異なる変数を別の変数に入れよう
int a = 1; int b = 1;
し、私は次のように別の変数に一緒にこれらの数字を入れたい:
int c=ab; // so the value here would be then 11.
変数に数値を保存する必要があります。2つの異なる変数を別の変数に入れよう
int a = 1; int b = 1;
し、私は次のように別の変数に一緒にこれらの数字を入れたい:
int c=ab; // so the value here would be then 11.
int c = (int) Math.pow(10, Math.floor(Math.log10(b))+1)*a + b.
コンプリートプログラム
class Main {
public static void main(String[] args) {
int a = 1234;
int b = 567890;
int c = (int) Math.pow(10, Math.floor(Math.log10(b))+1)*a + b;
System.out.println(c);
}
}
テスト
1234567890
あなたはonlineそれを試すことができます。
int a = 1;
int b = 1;
String ab = "" + a + b;
int c = Integer.parseInt(ab);
String
のように連結しましたか?
int c = Integer.parseInt("" + a + b);
、String
に変換連結し、Integer
に戻って解析します。
int a = 1, b = 1;
int c = Integer.parseInt("" + a + b);
String stringA = String.valueOf(a);
String stringB = String.valueOf(b);
String stringC = stringA + stringB;
あなたは少なくともJavaで、それを行うことはできません。
しかし、それは不可能ではありません。ここでは奇妙な方法です
int c=Integer.parseInt(a+""+b);
究極の目的が何であるか教えていただけたら、より良いアイデアを得ることができます。
文字列として保存しない限り、LOLは実行できません。 – Rahul
'int c = Integer.valueOf(String.valueOf(a)+ String.valueOf(b)); ' –
2つの数字?これを行う標準的な方法はありません。それはあなた次第です。 –