SDUT java lab 7.3

简介: SDUT java lab 7.3

7-3 sdut-JAVA-Common Plurals

分数 9

全屏浏览

切换布局

作者 马新娟

单位 山东理工大学

When forming plurals of common nouns that end in y in English the following rules are observed:

• Common nouns ending in y preceded by a vowel form their plurals by adding s, for example, bay, bays; key, keys; toy, toys.

• Common nouns ending in y preceded by a consonant or by qu change the y to i and add es, for example, city, cities; faculty, faculties; soliloquy, soliloquies; You should accept a word from the end user and if its plural can be formed using the rules specified here you should output the word input and its plural form otherwise, you should state that the plural form of the word cannot be formed using these rules.

Input Specification:

Accept a word from the end user.

Output Specification:

If its plural can be formed using the rules specified here you should output the word input and its plural form otherwise, you should state that the plural form of the word cannot be formed using these rules.

Sample Input:

bay

Sample Output:

bay in plural form is: bays
student

Sample Output:

Cannot form the plural form with the rules given.
soliloquy

Sample Output:

soliloquy in plural form is: soliloquies

代码长度限制

16 KB

时间限制

400 ms

内存限制

64 MB

栈限制

8192 KB

import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String arr = sc.nextLine();
        int n = arr.length();
        if(arr.charAt(n-1) != 'y'){
            System.out.println("Cannot form the plural form with the rules given.");
            System.exit(0);
        }
        else{
          if(arr.charAt(n-3) == 'q' && arr.charAt(n-2) == 'u'){
            
            System.out.print(arr+" in plural form is: " );
            for(int i = 0;i<arr.length()-1;i++){
              System.out.print(arr.charAt(i));
            }
            System.out.println("ies");
            System.exit(0);
          }
          else if(arr.charAt(n-2) == 'a' || arr.charAt(n-2) == 'e' ||arr.charAt(n-2) == 'i' ||arr.charAt(n-2) == 'o' ||arr.charAt(n-2) == 'u' ){
            System.out.println(arr+" in plural form is: " +arr+ "s");
          }
          else{
            System.out.print(arr+" in plural form is: " );
            for(int i = 0;i<arr.length()-1;i++){
              System.out.println(arr.charAt(i));
            }
            System.out.println("ies");
            System.exit(0);
 
          }
 
        }
 
       
}
}


目录
相关文章
|
Java
java lab 8------7-1 sdut-JAVA-a contacts list(s)(multi-arraylists)
java lab 8------7-1 sdut-JAVA-a contacts list(s)(multi-arraylists)
122 0
|
Java
SDUT JAVA lab3.9
SDUT JAVA lab3.9
136 2
|
Java
sdut java lab 7.1(法二好理解)
sdut java lab 7.1(法二好理解)
130 1
|
Java 应用服务中间件 AHAS
sdut java lab6主观题
sdut java lab6主观题
145 0
|
Java
SDUT Java lab6
SDUT Java lab6
105 0
|
Java
sdut java lab7单选
sdut java lab7单选
138 0
|
人工智能 Java
sdut java lab5
sdut java lab5
114 0
|
5月前
|
JSON 网络协议 安全
【Java】(10)进程与线程的关系、Tread类;讲解基本线程安全、网络编程内容;JSON序列化与反序列化
几乎所有的操作系统都支持进程的概念,进程是处于运行过程中的程序,并且具有一定的独立功能,进程是系统进行资源分配和调度的一个独立单位一般而言,进程包含如下三个特征。独立性动态性并发性。
270 1
|
5月前
|
JSON 网络协议 安全
【Java基础】(1)进程与线程的关系、Tread类;讲解基本线程安全、网络编程内容;JSON序列化与反序列化
几乎所有的操作系统都支持进程的概念,进程是处于运行过程中的程序,并且具有一定的独立功能,进程是系统进行资源分配和调度的一个独立单位一般而言,进程包含如下三个特征。独立性动态性并发性。
288 1
|
6月前
|
数据采集 存储 弹性计算
高并发Java爬虫的瓶颈分析与动态线程优化方案
高并发Java爬虫的瓶颈分析与动态线程优化方案