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


相关文章
sdut java lab6主观题
sdut java lab6主观题
57 0
|
10月前
|
sdut java lab5
sdut java lab5
48 0
|
8月前
|
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)
34 0
|
10月前
|
SDUT JAVA lab3.9
SDUT JAVA lab3.9
61 2
|
10月前
|
SDUT Java lab6
SDUT Java lab6
37 0
|
10月前
|
sdut java lab7单选
sdut java lab7单选
62 0
|
24天前
|
【Java并发】【线程池】带你从0-1入门线程池
欢迎来到我的技术博客!我是一名热爱编程的开发者,梦想是编写高端CRUD应用。2025年我正在沉淀中,博客更新速度加快,期待与你一起成长。 线程池是一种复用线程资源的机制,通过预先创建一定数量的线程并管理其生命周期,避免频繁创建/销毁线程带来的性能开销。它解决了线程创建成本高、资源耗尽风险、响应速度慢和任务执行缺乏管理等问题。
155 60
【Java并发】【线程池】带你从0-1入门线程池
Java网络编程,多线程,IO流综合小项目一一ChatBoxes
**项目介绍**:本项目实现了一个基于TCP协议的C/S架构控制台聊天室,支持局域网内多客户端同时聊天。用户需注册并登录,用户名唯一,密码格式为字母开头加纯数字。登录后可实时聊天,服务端负责验证用户信息并转发消息。 **项目亮点**: - **C/S架构**:客户端与服务端通过TCP连接通信。 - **多线程**:采用多线程处理多个客户端的并发请求,确保实时交互。 - **IO流**:使用BufferedReader和BufferedWriter进行数据传输,确保高效稳定的通信。 - **线程安全**:通过同步代码块和锁机制保证共享数据的安全性。
65 23
|
20天前
|
【源码】【Java并发】【线程池】邀请您从0-1阅读ThreadPoolExecutor源码
当我们创建一个`ThreadPoolExecutor`的时候,你是否会好奇🤔,它到底发生了什么?比如:我传的拒绝策略、线程工厂是啥时候被使用的? 核心线程数是个啥?最大线程数和它又有什么关系?线程池,它是怎么调度,我们传入的线程?...不要着急,小手手点上关注、点赞、收藏。主播马上从源码的角度带你们探索神秘线程池的世界...
91 0
【源码】【Java并发】【线程池】邀请您从0-1阅读ThreadPoolExecutor源码
Java社招面试题:一个线程运行时发生异常会怎样?
大家好,我是小米。今天分享一个经典的 Java 面试题:线程运行时发生异常,程序会怎样处理?此问题考察 Java 线程和异常处理机制的理解。线程发生异常,默认会导致线程终止,但可以通过 try-catch 捕获并处理,避免影响其他线程。未捕获的异常可通过 Thread.UncaughtExceptionHandler 处理。线程池中的异常会被自动处理,不影响任务执行。希望这篇文章能帮助你深入理解 Java 线程异常处理机制,为面试做好准备。如果你觉得有帮助,欢迎收藏、转发!
124 14