编程实现从键盘输入任意三个字符串,从中找出长度最大的一个并输出。
- 提问者网友:两耳就是菩提
- 2021-05-13 02:47
- 五星知识达人网友:罪歌
- 2021-05-13 03:58
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("输入第一个字符串:");
String str1 = sc.nextLine();
System.out.println("输入第二个字符串:");
String str2= sc.nextLine();
System.out.println("输入第三个字符串:");
String str3 = sc.nextLine();
if(str1.length()>str2.length()){
if(str1.length()>str3.length()){
System.out.println("str1最大:" + str1);
}else{
System.out.println("str3最大:" + str1);
}
}else{
if(str2.length()>str3.length()){
System.out.println("str2最大:" + str1);
}else{
System.out.println("str3最大:" + str1);
}
}
}
}
- 1楼网友:人间朝暮
- 2021-05-13 05:46
#include<stdio.h>
#define max(a,b) (a>b?a:b)
void main()
{
char str[1000];
char maxstr[1000];
int maxlen=0;
for(int i=0;i<3;i++)
{
scanf("%s",str);
if(maxlen<strlen(str))
{
maxlen=strlen(str);
strcpy(maxstr,str);
}
}
printf(maxstr);
}
- 2楼网友:十鸦
- 2021-05-13 05:07
这是我的一个7个字符数组的比较排序输出,你运行一下就明白了
Private Sub Command3_Click()
dim str(7)
str(0) = "ichi" str(1) = "Akita" str(2) = "Fukui" str(3) = "Fukuoka" str(4) = "Fukushima" str(5) = "Gifu" str(6) = "Kochi" str(7) = "Kumamoto" Dim arr As String Dim a(7) As String Dim temp As String Dim i As Integer
For i = 0 To 7
For j = 0 To 6 - i If (Len(str(j)) > Len(str(j + 1))) Then temp = str(j) str(j) = str(j + 1) str(j + 1) = temp End If Next j Next i For i = 0 To 7 print str(i) Next End Sub