hi evr1... im new to java and i am lost in this problem... help please...
input one number consisting of five digits from the user, separate the number into its individual digits and print the digits separated from one another by spaces each...
like when i enter 42339... the output should be:
4 2 3 3 9
help.....
6 replies to this topic
#1
Posted 30 November 2010 - 06:40 AM
|
|
|
#2
Posted 30 November 2010 - 07:16 AM
There are many ways in doing this.
I used the substring method and a for loop to do it. I know maybe this is not the best way but you can try it. :)
I used the substring method and a for loop to do it. I know maybe this is not the best way but you can try it. :)
#3
Posted 30 November 2010 - 07:25 AM
i really am new... *sigh* i tried to make one earlier.. and it went like this...
public class prelimActivity3 {
at the System.out part...
i'm really really new... and i don't know what to do.... thanks for the help...
public class prelimActivity3 {
public static void main (String args[]) {
String inarray=JOptionPane.showInputDialog ("Enter number array: ");
int a=Integer.parseInt (inarray);
int [] b={a};
System.out.println (b[]);
}
}
it had an error of .class expected...at the System.out part...
i'm really really new... and i don't know what to do.... thanks for the help...
#4
Posted 30 November 2010 - 08:34 AM
I amended your code a bit.
Actually I consider myself a beginner in java and I am not really good in it also. Hopefully it helps.
Regards.
public static void main (String args[]) {
int counter = 0;
int[] b;
b = new int[5];
while (counter < 5){
String inarray = JOptionPane.showInputDialog ("Enter 5 numbers: ");
int a = Integer.parseInt(inarray);
b[counter] = a;
counter++;
}
for(int i=0; i<b.length; i++){
System.out.print(b[i] + " ");
}
}
Actually I consider myself a beginner in java and I am not really good in it also. Hopefully it helps.
Regards.
#5
Posted 30 November 2010 - 08:55 AM
waaaaaaiiiii!!!!! Thank you very much!!!!! Thanks a lot!!!!:thumbup:
it was what i was looking for!!!!
acutally... i took up on your suggestion earlier about using substring... and it worked too... although the one i was looking for was using arrays... and you did it... waaaaaaaaaiiii!!!!!!!! Thank you again!!!!
you just saved meh life!!!!:thumbup:
it was what i was looking for!!!!
acutally... i took up on your suggestion earlier about using substring... and it worked too... although the one i was looking for was using arrays... and you did it... waaaaaaaaaiiii!!!!!!!! Thank you again!!!!
you just saved meh life!!!!:thumbup:
#6
Posted 30 November 2010 - 09:13 AM
Glad that it helps.
Anyway, hands-on practices will surely improve your skills in programming.
Good luck and happy programming.
Regards.
Anyway, hands-on practices will surely improve your skills in programming.
Good luck and happy programming.
Regards.
#7
Posted 30 November 2010 - 09:24 AM
Thanks again!!!! waaaaaaaaaaaiiiii!!!!!!!!!!!!!:thumbup:
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









