Saturday, 17 August 2013

How to cut a string given some parameters

How to cut a string given some parameters

public int cut(int b){
String str1;
b = 0;
Scanner str = new Scanner(System.in);
System.out.println("Write your string: ");
str1 = str.next();
Scanner in = new Scanner (System.in);
System.out.println("Write a number: ");
int num1 = in.nextInt();
System.out.println("Write another number: ");
int num2 = in.nextInt();
System.out.println(str1.substring(num1, num2));
return b;
}
This is my code so far. I want for a user to write a string and write from
where to where he wants to cut the string he just entered. The part I
can't get is getting that substring.

No comments:

Post a Comment