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");
        }
}
}


目录
相关文章
|
4月前
|
Java 应用服务中间件 AHAS
sdut java lab6主观题
sdut java lab6主观题
30 0
|
4月前
|
人工智能 Java
sdut java lab5
sdut java lab5
32 0
|
2月前
|
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)
17 0
|
4月前
|
Java
SDUT JAVA lab3.9
SDUT JAVA lab3.9
39 2
|
4月前
|
Java
SDUT Java lab6
SDUT Java lab6
22 0
|
4月前
|
Java
sdut java lab7单选
sdut java lab7单选
34 0
|
3天前
|
存储 缓存 Java
java线程内存模型底层实现原理
java线程内存模型底层实现原理
java线程内存模型底层实现原理
|
14天前
|
存储 缓存 安全
【Java面试题汇总】多线程、JUC、锁篇(2023版)
线程和进程的区别、CAS的ABA问题、AQS、哪些地方使用了CAS、怎么保证线程安全、线程同步方式、synchronized的用法及原理、Lock、volatile、线程的六个状态、ThreadLocal、线程通信方式、创建方式、两种创建线程池的方法、线程池设置合适的线程数、线程安全的集合?ConcurrentHashMap、JUC
【Java面试题汇总】多线程、JUC、锁篇(2023版)
|
8天前
|
缓存 Java 应用服务中间件
Java虚拟线程探究与性能解析
本文主要介绍了阿里云在Java-虚拟-线程任务中的新进展和技术细节。
|
5天前
|
Java 开发者
Java中的多线程基础与应用
【9月更文挑战第22天】在Java的世界中,多线程是一块基石,它支撑着现代并发编程的大厦。本文将深入浅出地介绍Java中多线程的基本概念、创建方法以及常见的应用场景,帮助读者理解并掌握这一核心技术。