sdut java lab 7.1(法二好理解)

简介: sdut java lab 7.1(法二好理解)

7-1 sdut-JAVA-Pig Latin

分数 12

全屏浏览

切换布局

作者 马新娟

单位 山东理工大学

Write a program that requests a word as input, translates the word into Pig Latin and outputs the word input and its equivalent in Pig Latin. The rules for translating a word are as follows:

Rule 1: If a word begins with a consonant, move the first letter to the end of the word and add ay to the end of the word. For example, Chip becomes hipCay.

Rule 2: If the word begins with a vowel, add way to the end of the word. For example, else becomes elseway.

Input Specification:

Request a word as input.

Output Specification:

Outputs the word input and its equivalent in Pig Latin.

Sample Input1:

Sample Output1:

No input provided to convert to Pig Latin.

Sample Input2:

123anksO

Sample Output2:

Input should comprise of alphabetic characters only.

Sample Output3:

123anksO

Sample Output3:

Input should comprise of alphabetic characters only.

Sample Output4:

day

Sample Output4:

Word Input: day

Pig Latin: ayday

代码长度限制

16 KB

时间限制

400 ms

内存限制

64 MB

栈限制

8192 KB

import java.util.Scanner;
public class Main
{
  public static void main(String[] args)
  {
        Scanner in=new Scanner(System.in);
      String arr=in.nextLine();
        if(arr.isBlank())
        {
            System.out.println("No input provided to convert to Pig Latin.");
            return;
        }
        int n=arr.length();
        for(int i=0;i<n;i++)
        {
            
        
         if(arr.charAt(i)>='1'&&arr.charAt(i)<='9')
        {
             System.out.println("Input should comprise of alphabetic characters only.");
            return;
        }
        }
       
    
       
        if(arr.charAt(0)=='a'||arr.charAt(0)=='e'||arr.charAt(0)=='i'||arr.charAt(0)=='o'||arr.charAt(0)=='u'||arr.charAt(0)=='A'||arr.charAt(0)=='E'||arr.charAt(0)=='I'||arr.charAt(0)=='O'||arr.charAt(0)=='U')
        {
            System.out.println("Word Input: "+arr);
            System.out.print("Pig Latin: "+arr+"way");
           
        }
        else{
            System.out.println("Word Input: "+arr);
            System.out.print("Pig Latin: ");
            for(int i=1;i<n;i++)
            {
                System.out.print(arr.charAt(i));
            }
            System.out.println(arr.charAt(0)+"ay");
        }
}
}


目录
相关文章
|
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)
118 0
|
Java
SDUT JAVA lab3.9
SDUT JAVA lab3.9
135 2
|
Java 应用服务中间件 AHAS
sdut java lab6主观题
sdut java lab6主观题
145 0
|
Java
SDUT Java lab6
SDUT Java lab6
103 0
|
Java
sdut java lab7单选
sdut java lab7单选
134 0
|
人工智能 Java
sdut java lab5
sdut java lab5
113 0
|
4月前
|
JSON 网络协议 安全
【Java】(10)进程与线程的关系、Tread类;讲解基本线程安全、网络编程内容;JSON序列化与反序列化
几乎所有的操作系统都支持进程的概念,进程是处于运行过程中的程序,并且具有一定的独立功能,进程是系统进行资源分配和调度的一个独立单位一般而言,进程包含如下三个特征。独立性动态性并发性。
266 1
|
4月前
|
JSON 网络协议 安全
【Java基础】(1)进程与线程的关系、Tread类;讲解基本线程安全、网络编程内容;JSON序列化与反序列化
几乎所有的操作系统都支持进程的概念,进程是处于运行过程中的程序,并且具有一定的独立功能,进程是系统进行资源分配和调度的一个独立单位一般而言,进程包含如下三个特征。独立性动态性并发性。
282 1
|
5月前
|
数据采集 存储 弹性计算
高并发Java爬虫的瓶颈分析与动态线程优化方案
高并发Java爬虫的瓶颈分析与动态线程优化方案
Java 数据库 Spring
243 0