# java int variable

posted 3 years ago

Can you show in an example what you mean?

I'm confused with the "2nd from the left" piece.

Also, since int is a primitive, you may want to convert it to a String.

WP

I'm confused with the "2nd from the left" piece.

Also, since int is a primitive, you may want to convert it to a String.

WP

Joanne Neal

Rancher

Posts: 3742

16

Campbell Ritchie

Sheriff

Posts: 49463

64

posted 3 years ago

Ok so now somehow I have written the code to find the digits separately.Below is the code.

BufferedReader k=new BufferedReader(new InputStreamReader(System.in));

System.out.println("enter a number");

try {

int num=Integer.parseInt(k.readLine());

int n=num;

System.out.println("number you entered is" +n);

String string=Integer.toString(n);

int[] digits=new int[string.length()];

System.out.println(digits);

for(int i=0;i<string.length();i++){

digits[i]= Integer.parseInt(string.substring(i,i+1));

}

System.out.println("thedigits are" +Arrays.toString(digits));

Now my intention is make the programme run like below..

I have an integer number lets say 4567.

The programme output will print 410614(every second digit will be added with it self)

example->

int num=4567.

second digit is four(4) here,so in output it will add 5+5=10

then fourth digit is seven(7) here,so in output it will be 7+7=14.

Finally it will give me the whole output as 410614.

got struck here.

BufferedReader k=new BufferedReader(new InputStreamReader(System.in));

System.out.println("enter a number");

try {

int num=Integer.parseInt(k.readLine());

int n=num;

System.out.println("number you entered is" +n);

String string=Integer.toString(n);

int[] digits=new int[string.length()];

System.out.println(digits);

for(int i=0;i<string.length();i++){

digits[i]= Integer.parseInt(string.substring(i,i+1));

}

System.out.println("thedigits are" +Arrays.toString(digits));

Now my intention is make the programme run like below..

I have an integer number lets say 4567.

The programme output will print 410614(every second digit will be added with it self)

example->

int num=4567.

second digit is four(4) here,so in output it will add 5+5=10

then fourth digit is seven(7) here,so in output it will be 7+7=14.

Finally it will give me the whole output as 410614.

got struck here.

posted 3 years ago

I have an integer number lets say 4567.

The programme output will print 410614(every second digit will be added with it self)

example->

int num=4567.

second digit is five(5) here,so in output it will add 5+5=10

then fourth digit is seven(7) here,so in output it will be 7+7=14.

Finally it will give me the whole output as 410614.

got struck here.

I have an integer number lets say 4567.

The programme output will print 410614(every second digit will be added with it self)

example->

int num=4567.

second digit is five(5) here,so in output it will add 5+5=10

then fourth digit is seven(7) here,so in output it will be 7+7=14.

Finally it will give me the whole output as 410614.

got struck here.

dennis deems

Ranch Hand

Posts: 808