Created
October 26, 2022 15:49
-
-
Save AhmadNader319/aa85e54273a908966b6086a6cff5940f to your computer and use it in GitHub Desktop.
strings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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