磕代码:c/c++/java:输入两行大写字母,输出小写字母;用while循环检测输入

这篇博客介绍了如何使用C、C++和Java编程语言,通过while循环实现用户输入两行大写字母并将其转换为小写字母的功能。示例代码分别展示了三种语言的实现方式。

在这里插入图片描述
在这里插入图片描述
c:

#include<stdio.h>
int main()
{
    char a;
    while(scanf("%c",&a)!=EOF){//EOF每一行结束的标志
        getchar();//吞掉回车键
        printf("%c\n",a+32);
    }
}

c++:

#include<bits/stdc++.h>
using namespace std;
int main(){
    char a,b;
    //cin>>(int)a>>(int)b;
    //a=a+32;
    //b=b+32;
    //cout<<a<<"\n"<<b;
    while(cin>>a){
        cout<<char(a+32)<<endl;
        //cout换行用endl;
    }
}

Java:

import java.io.*;
public class Main{
    public static void main(String[]args)throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        //String a=String
       // String str=null;
        String a;
        while((a=br.readLine())!=null){
            //System.out.printf("%c",a+32);
            System.out.println(a.toLowerCase());
        }
        //char b=s.charAt(1);
            //char的读取:https://blog.csdn.net/marcotsui/article/details/108139975
    }
}
//a.toLowerCase();null;while循环检测输入,不用两次都考虑
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值