This is IntelliJ jave Write a method which takes a number re
This is IntelliJ jave
Write a method which takes a number represented as a String as an argument, for example \"12345\" or \"4321432143214321\" and returns the digits of that number in an array.
Your method should create an int[] array with one digit of your number per element, and return this array.
So, if the user enters \"12345\" then your method should return this array : { 1, 2, 3, 4, 5 }
Solution
import java.util.*;
class Stringinput
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println(\"Enter The Number and then Press Enter\");
String str=s.nextLine();
get_value(str);
}
public static void get_value(String str)
{
String [] arr=str.split(\"\");
Integer [] a=new Integer[arr.length];
for(int i=0;i<arr.length;i++)
{
a[i]=Integer.parseInt(arr[i]);
}
for(int i=0;i<a.length;i++)
{
System.out.println(a[i]);
}
}
}
