Skip to content

Instantly share code, notes, and snippets.

@AhmadNader319
Created October 26, 2022 15:49
Show Gist options
  • Save AhmadNader319/aa85e54273a908966b6086a6cff5940f to your computer and use it in GitHub Desktop.
Save AhmadNader319/aa85e54273a908966b6086a6cff5940f to your computer and use it in GitHub Desktop.
strings
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//initialize inputs
String string1 , ss ;//ss is substring from string1 , ex) the substring(from index i to j) and print from i to j
int i , j ; // indexs of string1
//read initialized
System.out.println("enter the string to (substring) = ");
string1 = input.nextLine();
System.out.println("enter the first of index ");
i = input.nextInt();
System.out.println("enter the last of index () ");
j = input.nextInt();
if (j < i)
{
System.out.println("enter the end of index again (end>begin) = " );
j = input.nextInt();
}
//operations
int round =0;
while(round <string1.length())
{
if (round == i )
{
System.out.print(string1.charAt(round));
i++;
}
if (i == j)
{
break;
}
round++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment