Java 如何只使用两种字符串方法编写程序?

Java 如何只使用两种字符串方法编写程序?,java,Java,我正试图为我的家庭作业编写一个程序,在相同的索引下计算一个单词和一个句子的相同字符数 关键是用户写一个句子和一个单词,程序从相同的索引中计算相同的字符,并打印其数量。但如果单词比句子短,我必须将单词向右滑动一个空格,然后重复,直到单词的长度超过句子的长度 我只允许使用length和charAt作为字符串方法。我找不到最好的写作方法,我被卡住了 import java.util.Scanner; public class Question1 { public static void m

我正试图为我的家庭作业编写一个程序,在相同的索引下计算一个单词和一个句子的相同字符数

关键是用户写一个句子和一个单词,程序从相同的索引中计算相同的字符,并打印其数量。但如果单词比句子短,我必须将单词向右滑动一个空格,然后重复,直到单词的长度超过句子的长度

我只允许使用length和charAt作为字符串方法。我找不到最好的写作方法,我被卡住了

import java.util.Scanner;

public class Question1 {

    public static void main(String[] args) {

            Scanner keyboard = new Scanner(System.in);

            // asking a sentence from user
            System.out.println("Lütfen bir cümle giriniz."); 
            String sentence = keyboard.nextLine();

            //asking a word from user 
            System.out.println("Lütfen bir kelime giriniz."); 
            String word = keyboard.next();

            int sentenceLength = sentence.length();
            int wordLength = word.length();

            for (wordLength = 1; wordLength <= sentenceLength; wordLength++);

            word.length();
import java.util.Scanner;
公开课问题1{
公共静态void main(字符串[]args){
扫描仪键盘=新扫描仪(System.in);
//向用户询问一句话
System.out.println(“Lütfen bir cümle girizing.”);
字符串语句=keyboard.nextLine();
//向用户询问一句话
System.out.println(“Lütfen-bir-kelime-girizing.”);
字符串字=键盘。下一步();
int sentenceLength=句子长度();
int wordLength=word.length();
对于(wordLength=1;wordLength请使用while

import java.util.Scanner;

public class Main {
    public static final void main(String args[])
    {
        String word, sent;
        Scanner sc = new Scanner(System.in);
        System.out.print("sent->");
        sent=sc.nextLine();
        System.out.print("word->");
        word=sc.nextLine();
        while(word.length()<sent.length())
            word = word + ' ';
    }
}
import java.util.Scanner;
公共班机{
公共静态最终void main(字符串参数[])
{
字符串字,发送;
扫描仪sc=新的扫描仪(System.in);
系统输出打印(“发送->”;
sent=sc.nextLine();
系统输出打印(“word->”);
word=sc.nextLine();
while(word.length()