yegane8
شنبه 23 اردیبهشت 1391, 20:33 عصر
سلام
این برنامه که گذاشتم دو تا کلاسن که باید اگه کاربر جمله hello java world رو به عنوان جمله و کلمه java رو به عنوان کلمه وارد کرد در خروجی برنامه hello JAVA world چاپ شه ولی در این سورسی که من نوشتم فقط اگه کلمه java در جمله وجود داشت کلمه JAVA رو چاپ میکنه میشه دقیقا توضیح بدین که باید چی کار کنم تا کلمه های دیگه هم به همووون ترتیب که تو جمله بودن هم چاپ شن .
کلاس 1 :
import java.util.Scanner;
/**
* Write a description of class input here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class input
{
// instance variables - replace the example below with your own
private Scanner reader;
/**
* Constructor for objects of class input
*/
public input()
{
// initialise instance variables
reader = new Scanner(System.in);
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public String getSentence()
{
System.out.println("\nenter the sentence");
String sentence = reader.nextLine();
return sentence;
}
public String getWord()
{
System.out.println("\nenter the word u want to be capital");
String word = reader.nextLine();
return word;
}
}
کلاس 2:
import java.util.ArrayList;
import java.lang.String;
/**
* Write a description of class parser here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class parser
{
// instance variables - replace the example below with your own
private input inputer;
/**
* Constructor for objects of class parser
*/
public parser()
{
// initialise instance variables
inputer = new input();
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public void search(){
String sentec = inputer.getSentence();
String word = inputer.getWord();
if(sentec.contains(word)){
String[] wordArray = sentec.split(" ");
int m = sentec.indexOf(word);
System.out.println("exist");
// String[] wordArray = sentec.split(" ");
word.toUpperCase();
System.out.println(word.toUpperCase());
}
}
}
این برنامه که گذاشتم دو تا کلاسن که باید اگه کاربر جمله hello java world رو به عنوان جمله و کلمه java رو به عنوان کلمه وارد کرد در خروجی برنامه hello JAVA world چاپ شه ولی در این سورسی که من نوشتم فقط اگه کلمه java در جمله وجود داشت کلمه JAVA رو چاپ میکنه میشه دقیقا توضیح بدین که باید چی کار کنم تا کلمه های دیگه هم به همووون ترتیب که تو جمله بودن هم چاپ شن .
کلاس 1 :
import java.util.Scanner;
/**
* Write a description of class input here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class input
{
// instance variables - replace the example below with your own
private Scanner reader;
/**
* Constructor for objects of class input
*/
public input()
{
// initialise instance variables
reader = new Scanner(System.in);
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public String getSentence()
{
System.out.println("\nenter the sentence");
String sentence = reader.nextLine();
return sentence;
}
public String getWord()
{
System.out.println("\nenter the word u want to be capital");
String word = reader.nextLine();
return word;
}
}
کلاس 2:
import java.util.ArrayList;
import java.lang.String;
/**
* Write a description of class parser here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class parser
{
// instance variables - replace the example below with your own
private input inputer;
/**
* Constructor for objects of class parser
*/
public parser()
{
// initialise instance variables
inputer = new input();
}
/**
* An example of a method - replace this comment with your own
*
* @param y a sample parameter for a method
* @return the sum of x and y
*/
public void search(){
String sentec = inputer.getSentence();
String word = inputer.getWord();
if(sentec.contains(word)){
String[] wordArray = sentec.split(" ");
int m = sentec.indexOf(word);
System.out.println("exist");
// String[] wordArray = sentec.split(" ");
word.toUpperCase();
System.out.println(word.toUpperCase());
}
}
}