Java Algorithm regarding taking array of String and Integers to - java

I'm currently doing an activity that requires me to write this:
Write a definition for a static method stringHeads that inputs an array of ints p and a String s. For each of the ints n in p, the method builds the substring consisting of the first n characters in s (or the whole of s, if n is greater than the length of s). The method returns the array of these substrings.
My code is currently something like this:
public static String[] stringHeads(int[] p, String s) {
String[] rad = new String[p.length];
int e = 0;
for (int b : p)
e = b - 1
for (int de = 0; rad.length > de; de++)
rad[de] = s.substring(0,e);
for (String str : rad)
return str;
}
//Just ignore the rest
int[] a = {4, 2, 3, 2, 0 };
String b = "Radon"
stringHeads(a,b)
The output should be "Rado" , "Ra", "Rad", "Ra", "".
The error that I'm currently getting is that String cannot be converted to String[].
Basically my question is how to fix this error and if a better code can be written.

Three things:
e would be constant if you enter the second loop.
e could be larger than s.length() - you didn't handle this case.
You return a String instead of a String[]
And please always use braces if you use loops, even if the loop only contains one statement. It is much more readable and can avoid errors.
I think you will have to rethink your whole function. Don't know if it would be helpful to write the function for you.
Hints:
Write only one loop!
String[] rad = new String[p.length];
for (int i=0; i < p.length; i++) {
if (s.length() < ??) {
rad[i] = s.substring(0,??);
} else {
??
}
}
return rad;
I hope this will help you to get the answer yourself.

See my code below hope it helps:-
I provided the comments instead of explaining it in paragraph.
As for your error, you are returning String from method but expected is an array of String.
public static void main(String[] args){
int[] a = {4, 2, 3, 2, 0 };
String b = "Radon";
String[] output=stringHeads(a,b);
for(String s:output){
System.out.println(s);
}
}
Your method can be like below:
public static String[] stringHeads(int[] p, String s) {
String[] rad = new String[p.length];
int e = 0;
//Iterate over integer array
for(int index=0; index<p.length; index++){
//Extracting the integer value from array one by one
e=p[index];
//If integer value is greater than String length
if(e>s.length()){
//Put the entire String in String array
rad[index]=s;
}else{
//Put the Substring value with range 0 to e i.e. integer value
rad[index]=s.substring(0,e);
}
}
return rad;
}

You could simplify you code by just using a single iteration with an alternative variable.
public static void main (String[] args) throws java.lang.Exception
{
int[] a = {4, 2, 3, 2, 0 };
String b = "Radon";
String[] result = stringHeads(a,b);
for(String x : result) System.out.println(x);
//Or you can write a separate display method instead.
}
public static String[] stringHeads(int[] p, String s)
{
String[] rad = new String[p.length];
//Use this variable for array allocation/iteration.
int i=0;
//Simply iterate using this for-each loop.
// This takes care of array allocation/ substring creation.
for (int x : p)
rad[i++] = s.substring(0,x);
return rad;
}

Please check the code below
public static String[] stringHeads(int[] intArray, String str) {
String[] result = new String[intArray.length];
int count=0;
for (int intValue : intArray)
{
result[count] = str.substring(0,intValue);
count++;
}
return result;
} //Just ignore the rest
public static void main(String[] args) {
int[] a = {4, 2, 3, 2, 0 };
String b = "Radon";
String[] strArray=stringHeads(a,b);
int count=0;
for(String str:strArray)
System.out.println(++count+"" +str);
}

Change your method like this
public static String[] stringHeads(int[] p, String s) {
String[] rad = new String[p.length];
int e = 0;
for (int b : p) {
rad[e] = s.substring(0, b);
e++;
}
return rad;
}
For use this method
public static void main(String[] args) {
int[] a = {4, 2, 3, 2, 0};
String b = "Radon";
String[] stringHeads = stringHeads(a, b);
for (String stringHead : stringHeads) {
System.out.println(stringHead);
}
}
Output is
Rado
Ra
Rad
Ra

There is no need for the for loop that iterates through the integer array p
public static String[] stringHeads(int[] p, String s) {
String[] rad = new String[p.length];
for (int de = 0; de < p.length; de++){
if (p[de] < s.length())
rad[de] = s.substring(0,p[de]);
else
rad[de]=s;
}
return rad;
}

public static String[] stringHeads(int[] p, String s) {
String[] rad = new String[p.length];
int e = 0;
for (int b : p) {
if(b<=s.length()){
rad[e] = s.substring(0, b);
}
e++;
}
return rad;
}

Related

Remix the String

I am stuck with this challenge, any help would be great.
'Create a function that takes both a string and an array of numbers as arguments. Rearrange the letters in the string to be in the order specified by the index numbers. Return the "remixed" string. Examples
remix("abcd", [0, 3, 1, 2]) ➞ "acdb"'
My attempt -
package edabitChallenges;
//Create a function that takes both a string and an array of numbers as arguments.
//Rearrange the letters in the string to be in the order specified by the index numbers.
//Return the "remixed" string.
public class RemixTheString {
public static String remix(String word, int[] array) {
char[] wordArray = word.toCharArray();
for (int i = 0; i < array.length; i++) {
char ch = ' ';
ch = wordArray[i];
wordArray[i] = wordArray[array[i]];
wordArray[array[i]] = ch;
}
String newString = new String(wordArray);
return newString;
}
public static void main(String[] args) {
System.out.println(remix("abcd", new int[] { 0, 3, 1, 2 }));
}
}
I would suggest just iterating the indices passed in the array[] input, and then building out the output string:
public static String remix(String word, int[] array) {
char[] wordArray = word.toCharArray();
StringBuilder output = new StringBuilder();
for (int i=0; i < array.length; i++) {
output.append(wordArray[array[i]]);
}
return output.toString();
}
public static void main(String[] args) {
System.out.println(remix("abcd", new int[] { 0, 3, 1, 2 })); // adbc
}
Here we use StringBuilder which exposes a handy append(char) method for adding one character at a time to the string in progress.

Leetcode 833: String replacement depend upon index numbering

String index value accessThis question is a part of my previous question .
Example 1:
Input: S = "abcd", indexes = [0,2], sources = ["a","cd"], targets = ["eee","ffff"]
Output: eeebffff
Explanation: a starts at index 0 in S, so it's replaced by eee.
cd starts at index 2 in S, so it's replaced by ffff.
Example 2:
Input: S = "abcd", indexes = [0,2], sources = ["ab","ec"], targets = ["eee","ffff"]
Output: "eeecd"
Explanation: "ab" starts at index 0 in S, so it's replaced by "eee".
"ec" doesn't starts at index 2 in the original S, so we do nothing.
public class Q833 {
public static void main(String args[]){
String S="abcd";
int[] indexes = {0, 2};
String[]sources={"ab","cd"};
String[] targets = {"eee", "ffff"};
Solve833 ob833=new Solve833();
System.out.println(ob833.findReplaceString(S,indexes,sources,targets));
}
}
class Solve833{
public String findReplaceString(String S, int[] indexes, String[] sources, String[] targets) {
char[] array = S.toCharArray();
StringBuilder result = new StringBuilder();
int counter = 0;
String s = "";
for (String n:sources)
s+= n;
char[] c = s.toCharArray();
for (int i = 0; i < array.length; i++) {
if(array[indexes[counter]]==c[counter]){
result.append(targets[counter]);
if(counter<=indexes.length) {
counter++;
}
}
else
result.append(array[i]);
}
return result.toString();
}
}
Code Output: for 1st example
Expected output:Output: "eeebffff".
My output:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at Leetcode.Solve833.findReplaceString(Q833.java:30) at
Leetcode.Q833.main(Q833.java:16)
Code Output:2nd example
Expected Output: "eeecd"
My Output: eeebcd. So here a b missing. How can I handle it?
Your problem is that you should NOT do array[indexes[counter]]==c[counter] to determine that if the i-thsource string is presented in the S at index i. Your juegement only check for the first character of the source string.
The key of this problem is how can we find the index correctly, as when we are trying to get the result, the index(where to replce the source string with target string) may change.
try this code:
public String findReplaceString(String S, int[] indexes, String[] sources, String[] targets) {
StringBuilder sb=new StringBuilder(S);
int[] offsets=new int[indexes.length];
for(int i=0;i<indexes.length;i++){
if(S.substring(indexes[i],indexes[i]+sources[i].length()).equals(sources[i])){
int offset=0;
for(int j=0;j<i;j++){
if(indexes[j]<indexes[i])
offset+=offsets[j];
}
sb.replace(indexes[i]+offset,indexes[i]+sources[i].length()+offset,targets[i]);
offsets[i]=targets[i].length()-sources[i].length();
}
}
return sb.toString();
}
You can change your method like this to print the result,
public class Q833 {
public static void main(String args[]) {
String S = "abcd";
int[] indexes = {0, 2};
String[] sources = {"a", "cd"};
String[] targets = {"eee", "ffff"};
Solve833 ob833 = new Solve833();
System.out.println(ob833.findReplaceString(S, indexes, sources, targets));
}
}
class Solve833 {
public String findReplaceString(String S, int[] indexes, String[] sources, String[] targets) {
StringBuffer result = new StringBuffer(S);
for (int i = 0; i < indexes.length; i++) {
if (sources[i].equals(result.substring(indexes[i], indexes[i] + sources[i].length()))) {
result.replace(indexes[i], indexes[i] + sources[i].length(), targets[i]);
if (i < indexes.length - 1)
indexes[i + 1] = indexes[i + 1] + targets[i].length() - sources[i].length();
}
}
return result.toString();
}
}

Java substring method giving IndexOutOfBoundsException

I am trying to separate String [] adr = {"Tel Iva +38712345", "Mail Iva ivag#gmail.com", "Tel Ana +12345678"} by looking at each of the element's first word. If the first word is Mail, it goes to String [] m, and if the first word is Tel, it goes to String [] t.
Here is my code:
public static void rep(String a, String []adr) {
int mail=0, tel=0;
for (int i=0; i<adr.length; i++) {
if(adr[i].substring(0, 3).equals("Mail")) {
mail++;
}
else tel++;
}
String [] m = new String [mail];
String [] t = new String [tel];
for(int i=0; i<adr.length; i++) {
if(adr[i].substring(0, 4).equals("Mail")) {
m[i]=adr[i].substring(5);
}
else t[i]=adr[i].substring(4);
System.out.println(adr[i].substring(0, 4));
}
}
But for some reason unknown to me, I get
Exception in thread "main"
java.lang.ArrayIndexOutOfBoundsException: 1
which points at line m[i]=adr[i].substring(5). I really do not understand why. Any help would be appreciated.
Correct Solution. you need to two indices to track m and t array traversal.
public static void rep(String a, String []adr) {
int mail=0, tel=0;
for (int i=0; i<adr.length; i++)
{
if(adr[i].substring(0, 4).equals("Mail")) {
mail++;
}
else tel++;
}
String [] m = new String [mail];
String [] t = new String [tel];
int mIndex =0, tIndex = 0;
for(int i=0; i<adr.length; i++) {
if(adr[i].substring(0, 4).equals("Mail")) {
m[mIndex]=adr[i].substring(4);
mIndex++;
}
else
{
t[tIndex]=adr[i].substring(4);
tIndex++;
}
System.out.println(adr[i].substring(0, 4));
}
}
Well You can try this method, I once coded same type of problem when I was learning Java for the my academics. Well you can also try StringTokenizer method to do the same. Maybe they works better. I am expecting that you are going to insert the whole string not splitted one.
import java.util.*;
import java.lang.*;
import java.*;
public class stringtoken{
public static void main(String args[]){
List<String> m=new ArrayList<String>();
List<String> t=new ArrayList<String>();
String[] s={"Tel Iva +38712345", "Mail Iva ivag#gmail.com", "Tel Ana +12345678"};
for(int i=0;i<s.length;i++){
if(s[i].indexOf("Tel")==0){
t.add(s[i]);
}
else if(s[i].indexOf("Mail")==0){
m.add(s[i]);
}
}
for(int i=0;i<m.size();i++){
System.out.println(m.get(i));
}
for(int i=0;i<t.size();i++){
System.out.println(t.get(i));
}
}
}
Supposedly index you used in the substring method are correct and I will only talk about index of the array :
String [] adr = {"Tel Iva +38712345", "Mail Iva ivag#gmail.com", "Tel Ana +12345678"}
By this data,
mail array's size will be 1, max index can use for mail array is 0
tel array's size will be 2, max index can use for tel array is 1
for(int i=0; i<adr.length; i++) {
if(adr[i].substring(0, 4).equals("Mail")) {
m[i]=adr[i].substring(5);
}
else t[i]=adr[i].substring(4);
System.out.println(adr[i].substring(0, 4));
}
In this loop :
LOOP 1 : i = 0 -> t[0]=xxx; -> OK
LOOP 2 : i = 1 -> m[1]=xxx; -> ERROR, because size of m array is 1, index can only be 0
PS : you need to check the index used in substring method
suppose this sample address array (your parameter adr[])
adr[0] = Maila#a.com
adr[1] = Tele123456
adr[2] = Mailb#a.com
adr[3] = Tele123456
adr[4] = Mailc#a.com
After your first loop which is assign values to int mail and tel
mail = 3;
tel = 2
so your m and t array looks like below.
String [] m = new String [3];
String [] t = new String [2];
What happen is in your last for looping for adr (you parameter array) length which is 5.
and try to assign values to m or t, by index of adr array.
Ex : adr[3] = Tele123456
on your second loop when i = 3 your getting this value and try to assign this value to
t[3] = 123456
where actually t size is 2 and then it occur array out of bound exception.
Hope you understood the issue on your code.
Rather than array for m and t use List.
Consider below example.
public static void rep(String a, String []adr) {
List<String> mails = new ArrayList<>();
List<String> teles = new ArrayList<>();
for (int i=0; i<adr.length; i++) {
if(adr[i].substring(0, 3).equals("Mail")) {
mails.add(adr[i].substring(5));
} else {
mails.add(adr[i].substring(5));
}
}
}
**Note : please fix compile errors if there.

Returning a String Array

import java.util.Random;
import java.util.Scanner;
public class ArrayHelpers{
public static void main(String[] args){
String arr[] = {"M3", "M4", "M5", "M6", "X5M", "M750Li"};
String stockElements[] = {"BMW M2 Coupé","BMW M3 Sedan", "BMW M4 Coupé", "BMW M5 Sedan","BMW M6 Gran Coupé", "BMW X5 M", "BMW X6 M", "M 750Li"};
int size = 7;
printArrayQuantities(arr);
System.out.println(getRandomElement(arr));
System.out.println(getRandomArray(size, stockElements));
}
public static void printArrayQuantities(String[] arr){
int num[] = {2, 1, 3, 3, 5, 1};
for( int i = 0; i < num.length; i++){
System.out.println(arr[i] + " " + num[i]);
}
}
public static String getRandomElement(String[] arr){
int randomNum = 0 + (int)(Math.random() * 6);
return arr[randomNum];
}
public static String[] getRandomArray(int size, String[] stockElements){
String[] randArray = new String[size];
for( int i = 0; i < size; i++){
randArray[i] = getRandomElement(stockElements);
}
return randArray;
}
}
So I'm trying to return an array that has been randomly inserted with elements from stockElements through getRandomElement method. When I'm trying to print that array from line 12 (System.out.println(getRandomArray(size, stockElements));) it produces [Ljava.lang.String;#6d06d69c as output. I'm aware of the .toString() method, but a requirement of my assignment is that I do not use any built in array methods. How exactly would I go about doing this?
A simple solution is just to iterate over it with for each loop.
String[] myArray = getRandomArray(size, stockElements); // this stores a reference of the returned array.
for(String str : myArray){
System.out.println(str);
}
or with for loop if you prefer.
String[] myArray = getRandomArray(size, stockElements); // this stores a reference of the returned array.
for(int i = 0; i < myArray.length; i++){
System.out.println(myArray[i]);
}
Since your function is returning an array, when you try to print the array you should be iterating through each elements with a for/while loop and printing them individually. Since you're trying to print the array variable it instead prints java's handle for it. So try something like this
String[] randomArray = getRandomArray(size, stockElements);
for (String s : randomArray) {
System.out.println(s);
}
Replace System.out.println(getRandomArray(size, stockElements)); with
String [] output = getRandomArray(size, stockElements);
printArrayQuantities(output);
You already have the array returned, just need to assign it:
String[] newArray = getRandomArray(size, stockElements);
But... if you want to just print it go with the below.
Using Java 8:
String.join(delimiter, newArray);
or (for older Java):
StringBuilder builder = new StringBuilder();
for(String s : newArray) {
builder.append(s);
builder.append(delimeter);
}
return builder.toString();

Getting data from a given String separated by (,,-) in java

I am having a String like this "5006,3030,8080-8083".
I want each element separately from the String:
5006
3030
8080
8081
8082
8083
Here's my code:
int i=0,j=0;
String delim = "[,]";
String hyphon = "[-]";
String example = "5006,3030,8080-8083";
String p[] = example.split(delim);
int len = p.length;
for(i=0;i<len;i++) {
String ps[]=p[i].split(hyphon);
if(ps.length>1) {
int start = Integer.parseInt(ps[0]);
int finish = Integer.parseInt(ps[1]);
int diff = finish-start+1;
for(j=0;j<diff;j++) {
System.out.println(start+j);
}
} else if(ps.length==1) {
System.out.println(ps[0]);
}
}
Is there any better solution or any class that simplifies my code?
I also want the numbers in a ascending order.
Try this code :
public static void main(String[] args) {
String input = "5006,3030,8080-8083";
List<Integer> list = new ArrayList<Integer>();
String[] numbers = input.split(",");
for (String s : numbers) {
if (s.contains("-")) {
String[] range = s.split("-");
int from = Integer.parseInt(range[0]);
int to = Integer.parseInt(range[1]);
for (int i = from; i <= to; i++) {
list.add(i);
}
}
else {
list.add(Integer.parseInt(s));
}
}
System.out.println("in asc order");
Collections.sort(list);
System.out.println(list.toString());
System.out.println("in desc order");
Collections.reverse(list);
System.out.println(list.toString());
}
My output :
in asc order
[3030, 5006, 8080, 8081, 8082, 8083]
in desc order
[8083, 8082, 8081, 8080, 5006, 3030]
I also want the numbers in a ascending order.
This adds an unexpected twist to your whole program, because once you realize that printing-as-you-go no longer works, you need to start almost from scratch.
The first thing to do is picking an appropriate representation. It appears that you represent ranges of integers, so start by defining a class for them:
class IntRange : Comparable<IntRange> {
private int low, high;
public int getLow() {return low;}
public int getHigh() {return high;}
public IntRange(int low, int high) {
// Add range check to see if low <= high
this.low = low; this.high = high;
}
public IntRange(int point) {low = high = point;}
#Override
public void print() {
for (int i = low ; i <= high ; i++) {
System.out.println(i);
}
}
#Override
public int compareTo(IntRange other) {
...
}
}
Now you can use your code to split on [,], then split on [-], construct IntRange, and put it into an ArrayList<IntRange>. After that you can use sort() method to sort the ranges, and print them in the desired order.
But wait, there is more to your problem than meets the eye. Think what would happen for input like this:
1,5,3-7,6
Where should 5 and 6 be printed? It is not good to print it before or after 3-7, so the trick is to remove points inside ranges.
But even that's not all: what do you do about this input?
1-5,3-7
You should print numbers 1 through 7, inclusive, but this would require merging two ranges. There is a good data structure for doing this efficiently. It is called a range tree. If your input is expected to be large, you should consider using range tree representation.
You are good to go; you can minimize the counter variables using enhanced for loop and while loop.
String example = "5006,3030,8080-8083";
String[] parts=example.split(",")
ArrayList<Integer> numbers = new ArrayList<Integer>();
for(String part: parts)
{
if(part.contains("-"))
{
String subParts[]=part.split("-");
int start = Integer.parseInt(subParts[0]);
int finish = Integer.parseInt(subParts[1]);
while(start <= finish)
{
numbers.add(start);
System.out.println(start++);
}
}
else {
System.out.println(part);
numbers.add(Integer.parseInt(part));
}
}
Integer[] sortedNumbers = new Integer[numbers.size()];
sortedNumbers = Arrays.sort(numbers.toArray(sortedNumbers));
Update (from comment):
Numbers are sorted now.
Try this
String str = "5006,3030,8080-8083";
String[] array = str.split(",");
String ans = "";
for(int i = 0; i < array.length; i++){
if(array[i].contains("-")){
String[] array2 = array[i].split("-");
int start = Integer.parseInt(array2[0]);
int end = Integer.parseInt(array2[array2.length - 1]);
for(int j = start; j <= end; j++){
ans = ans + j + ",";
}
}
else{
ans = ans + array[i] + ",";
}
}
System.out.print(ans);
This code assumes all integers are positive.
public static void main(String[] args) {
String testValue="5006,3030,8080-8083";
Integer[]result=parseElements(testValue);
for (Integer i:result){
System.out.println(i);
}
}
/**
* NumberList is a string of comma-separated elements that are either integers, or a range of integers of the form a-b.
* #param numberList
* #return all the integers in the list, and in ranges in the list, in a sorted list
*/
private static Integer[] parseElements(String integerList) {
ArrayList<Integer> integers=new ArrayList<Integer>();
String[] csvs=integerList.split(",");
for(String csv : csvs){
if(csv.contains("-")){
String[] range=csv.split("-");
Integer left=Integer.decode(range[0]);
Integer right=Integer.decode(range[1]);
for(Integer i=left;i<=right;i++){
integers.add(i);
}
} else {
integers.add(Integer.decode(csv));
}
}
Collections.sort(integers);
return integers.toArray(new Integer[0]);
}
Using Guava's functional idioms you can achive this declaratively, avoiding the verbose, imperative for-loops. First declare a tokenizing function which converts each token in the comma-delimited string into an Iterable<Integer>:
private static final Function<String, Iterable<Integer>> TOKENIZER =
new Function<String, Iterable<Integer>>() {
/**
* Converts each token (e.g. "5006" or "8060-8083") in the input string
* into an Iterable<Integer>; either a ContiguousSet or a List with a
* single element
*/
#Override
public Iterable<Integer> apply(String token) {
if (token.contains("-")) {
String[] range = token.trim().split("-");
return ContiguousSet.create(
Range.closed(Integer.parseInt(range[0]),
Integer.parseInt(range[1])),
DiscreteDomain.integers());
} else {
return Arrays.asList(Integer.parseInt(token.trim()));
}
}
};
then apply the function to the input:
String input = "5006,3030,8080-8083";
Iterable<String> tokens = Splitter.on(',').trimResults().split(input);
SortedSet<Integer> numbers = Sets.newTreeSet();
Iterables.addAll(numbers,
// concat flattens the Iterable<Iterable<Integer>>
// into an Iterable<Integer>
Iterables.concat(Iterables.transform(tokens, TOKENIZER)));
As all of the logic is basically coded into the Function, the client code only needs to tokenize the string into an Iterable<String> (with Splitter), apply the Function through Iterables.transform, flatten the result of the transformation using Iterables.concat and finally add the resulting Iterable<Integer> into a SortedSet<Integer> which keeps the numbers in ascending order.
with java 8 stream api :
public static void main(String[] args) {
String s = "5006,3030,8080-8083";
Arrays.stream(s.split(","))
.flatMap(el -> el.contains("-") ? rangeToStream(el) : Stream.of(Integer.valueOf(el)))
.sorted()
.forEachOrdered(e -> System.out.println(e));
}
private static Stream<? extends Integer> rangeToStream(String el) {
AtomicInteger[] bounds = Arrays.stream(el.split("-")).map(e -> new AtomicInteger(Integer.parseInt(e))).toArray(size -> new AtomicInteger[2]);
return Arrays.stream(new Integer[bounds[1].get() - bounds[0].get() + 1]).map(e -> bounds[0].getAndIncrement());
}
U can code something like this -
String s="5006,3030,8080-8083";
String s2[]=s.split(",");
List<Integer> li= new ArrayList<Integer>();
List<Integer> numbers= new ArrayList<Integer>();
for(int i=0;i<s2.length;i++){
if(s2[i].contains("-")){
li.add(i);
}
else{
numbers.add(Integer.parseInt(s2[i]));
}
}
for(Integer i:li){
String str=s2[i];
String strArr[]=str.split("-");
for(int j=Integer.parseInt(strArr[0]);j<=Integer.parseInt(strArr[1]);j++){
numbers.add(j);
}
}
Collections.sort(numbers);
for(Integer k:numbers){
System.out.println(k);
}
public static void main(String[] args)
{
String example = "5006,3030,8080-8083";
String[] splitString = example.split(",");
List<Integer> soretedNumbers = new ArrayList<>();
for(String str : splitString)
{
String[] split2 = str.split("-");
if(split2.length == 1)
{
soretedNumbers.add(Integer.parseInt(str));
}
else
{
int num1 = Integer.parseInt(split2[0]);
int num2 = Integer.parseInt(split2[1]);
for(int i = num1;i <= num2; i++)
{
soretedNumbers.add(i);
}
}
}
Collections.sort(soretedNumbers);
for(int i : soretedNumbers)
{
System.out.println(i);
}
}

Categories