在JAVA中,编写程序提示用户输入两个字符串,并检验第一个字符串是否为第二个字符串的子串 你好,能告诉我如何用java编写这个程序 嘛,提示用户输入两...
\u7528\u6237\u8f93\u5165\u4e24\u4e2a\u5b57\u7b26\u4e32,\u68c0\u9a8c\u7b2c\u4e00\u4e2a\u662f\u5426\u4e3a\u7b2c\u4e8c\u4e2a\u7684\u5b50\u4e32 \u7528JAVA\u7f16\u5199s1.indexof(s2)
\u5982\u679c\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u7a9c\u662f\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32\u7684\u5b50\u4e32\u5c06\u8fd4\u56de\u5b50\u4e32\u5728s1\u4e2d\u7684\u8d77\u59cb\u4e0b\u6807\uff0c\u5982\u679c\u4e0d\u662f\u5c06\u8fd4\u56de-1
\u697c\u4e3b\u4f60\u597d \u53ef\u4ee5\u7528Scanner\u53bb\u8f93\u5165\u7136\u540e\u8c03\u7528\u5b57\u7b26\u4e32\u7684equals\u65b9\u6cd5\u8fd4\u56detrue\u6216false \u5f88\u7b80\u5355\u7684\u7a0b\u5e8f \u81ea\u5df1\u53bb\u7ec3\u4e60\u4e00\u4e0b\u6bd4\u522b\u4eba\u7ed9\u4f60\u90fd\u6572\u51fa\u6765\u8981\u597d\u5f97\u591a
String 有个方法contains可以用来检测子串import java.io.*;
import java.util.*;
public class test
{
public static void main(String[] args)
{
Scanner sin=new Scanner(System.in);
String str1=sin.next();
String str2=sin.next();
if(str2.contains(str1))
System.out.println("Yes");
else
System.out.println("No");
}
}
绛旓細浣跨敤寰幆缁撴瀯锛屽湪寰幆浣撲腑鎻愮ず鐢ㄦ埛杈撳叆锛屽苟鍒ゆ柇鐢ㄦ埛杈撳叆鐨勫瓧绗︽槸鍚︽纭銆傚鏋滅敤鎴疯緭鍏ョ殑瀛楃涓嶆纭紝鍒欐彁绀虹敤鎴烽噸鏂拌緭鍏ャ傚鏋滅敤鎴疯緭鍏ョ殑瀛楃姝g‘锛屽垯閫鍑哄惊鐜傚湪寰幆浣撳浣跨敤璇诲彇鐨勫瓧绗︺備笅闈㈡槸涓涓ず渚嬩唬鐮:import java.util.Scanner;public class Main { public static void main(String[] args) { Scann...
绛旓細String 鏈変釜鏂规硶contains鍙互鐢ㄦ潵妫娴嬪瓙涓 import java.io.*;import java.util.*;public class test { public static void main(String[] args){ Scanner sin=new Scanner(System.in);String str1=sin.next();String str2=sin.next();if(str2.contains(str1))System.out.println("Yes");else ...
绛旓細浣犵殑绋嬪簭锛岄敊璇お澶氫簡銆1锛変綘name鍜実rade鍙兘淇濆瓨鏈鍚庝竴涓緭鍏ョ殑鍊硷紝涓嶈兘寰幆杈撳叆銆2锛夊ぇ姒傜湅浜嗕竴涓嬩綘鐨勬帓搴忥紝娌℃湁姹傝瘉锛屾槸閿欒鐨勶紝姣斿鏁扮粍浼氳秺鐣屻3锛夎緭鍑烘帓搴忓悗鐨勫唴瀹癸紝鏈鍚庝袱鍙ヤ唬鐮侊紝浣犲皢杈撳嚭鍐欏湪浜嗘帓搴忕殑浠g爜閲岋紝鎺掑簭杩樻病鏈夋帓濂斤紝杈撳嚭鐨勪笉鍙兘姝g‘銆...鏈涓ラ噸鐨勫氨鏄涓鏉′簡锛屼綘寰楃湅鐪婮ava鐨...
绛旓細涓嬮潰鏄娇鐢Java缂栧啓鐨绋嬪簭锛屽彲浠鎻愮ず鐢ㄦ埛杈撳叆绗涘崱灏斿钩闈笂鏌愪竴鐐圭殑x,y鍧愭爣锛屽苟鍦ㄥ睆骞曚笂杈撳嚭璇ョ偣鏄鍑犺薄闄愭垨鑰呬綅浜庡潗鏍囪酱涓娿俙``import java.util.Scanner;public class CartesianPlane { public static void main(String[] args) { Scanner input = new Scanner(System.in);System.out.print("璇疯緭鍏...
绛旓細String eL = "[0-9]{3}-[0-9]{2}-[0-9]{5}"; Pattern p = Pattern.compile(eL); String test = "232-23-33333"; Matcher m = p.matcher(test); boolean dataFlag = m.matches(); if (!dataFlag) { System.out.println("鏍煎紡閿欒"); }else{ System...
绛旓細public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in);System.out.print("Enter the size for the matrix: ");int size = input.nextInt();int [][] array = new int [size][size];for(int i = 0;i<size;i++) ...
绛旓細import java.util.Scanner;public class Test{ public static void main(String[] args){ System.out.print("Enter the number of second:");Scanner sc = new Scanner(System.in);int second = sc.nextInt();for(int i = second;i>0;i--){ System.out.println(i+" seconds remaining");...
绛旓細import java.util.Scanner;public class $ { private static int[] DAYS = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("杈撳叆骞翠唤:"); int year =...
绛旓細package test;import java.util.Scanner;public class test {public static void main(String[] args) {while(true){Scanner input=new Scanner(System.in);System.out.print("璇疯緭鍏ュ甫瀛楁瘝鐨勫瓧绗︿覆锛");String str1=input.next(); int counA=0;int couna=0; for(int i=0;i<str1.le...
绛旓細import java.util.Scanner;import java.util.Stack; public class MinimalElements { private static Stack<Integer> getElements(int val) { Stack<Integer> result = new Stack<Integer>(); int prime = 2; while (val > 1) { while (!isPrime(prime)) { prime++; } ...