public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.next(); String ss = s.toUpperCase(); if(s.equals(ss)){ System.out.println("大写!"); System.out.println("转成:"+s.toLowerCase()); }else{ System.out.println("小写!"); System.out.println("转成:"+s.toUpperCase()); }
}
public static void main(String[] args) {
int count = 97; int y = 1; for(int i=3; i>0; i--){ for(int j=0; j<i-1; j++){ System.out.print(" "); }
for(int k = 0;k < y; k++) System.out.print((char)count); System.out.println(); y = y + 2; count++;
} }
没怎么考虑,很简单的算法, 我你把count的值换下, 我的是小写的A..
public class pic { private static int n=5; private static char[] ch={'A','B','C','D','E','F','G'}; public static void main(String[] args) throws Exception{
(1)import java.util.Scanner;public class SwitchCase {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); System.out.println("请输入字符:"); String input = scanner.next(); if (input != null) { for (int i = 0; i < input.length(); i++) System.out.print(switchCase(input.charAt(i))); } }
public static char switchCase(char c) { if (!Character.isLetter(c)) return c; if (Character.isUpperCase(c)) return Character.toLowerCase(c); return Character.toUpperCase(c); } } (2)public class Triangle {
public static void main(String[] args) { triangle('A', 'Z'); }
public static void triangle(char from, char to) { if (to < from) return; int height = to - from; for (int i = 0; i <= height; i++) { for (int j = 0; j < height-i; j++) System.out.print(' '); for (int j = 0; j < (i+1)*2-1; j++) System.out.print((char)(from + i)); System.out.println(); } } }
public static void main(String args[]){ char[] cha = {'A', 'B', 'C', 'D', 'E'}; print(cha); }
public static void print(char[] cha){ int len = cha.length; for (int i = 0; i < len; i++) { for (int j = 1; j < len - i; j++) { System.out.print(" "); } for (int j = 0; j < 2 *i + 1; j++) { System.out.print(cha[i]); } System.out.println(); } }
public static char exchange(char c){
char res = c;
if (c >= 'a' && c <= 'z')
res -= 32;
else if (c >= 'A' && c <='Z')
res += 32;
return res;
}
public static void main(String args[]){
System.out.print(exchange('c') +" "+ exchange('C'));
}
}
Scanner sc = new Scanner(System.in);
String s = sc.next();
String ss = s.toUpperCase();
if(s.equals(ss)){
System.out.println("大写!");
System.out.println("转成:"+s.toLowerCase());
}else{
System.out.println("小写!");
System.out.println("转成:"+s.toUpperCase());
}
}
int count = 97;
int y = 1;
for(int i=3; i>0; i--){
for(int j=0; j<i-1; j++){
System.out.print(" ");
}
for(int k = 0;k < y; k++)
System.out.print((char)count);
System.out.println();
y = y + 2;
count++;
}
}
private static int n=5;
private static char[] ch={'A','B','C','D','E','F','G'};
public static void main(String[] args) throws Exception{
for(int i=1;i<=n;i++){
for(int j=0;j<2*n-2*i;j++){
System.out.print(" ");
}
for(int k=0;k<(2*i-1);k++){
System.out.print(ch[i-1]);
}
System.out.println();
}
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入字符:");
String input = scanner.next();
if (input != null) {
for (int i = 0; i < input.length(); i++)
System.out.print(switchCase(input.charAt(i)));
}
}
public static char switchCase(char c) {
if (!Character.isLetter(c)) return c;
if (Character.isUpperCase(c))
return Character.toLowerCase(c);
return Character.toUpperCase(c);
}
}
(2)public class Triangle {
public static void main(String[] args) {
triangle('A', 'Z');
}
public static void triangle(char from, char to) {
if (to < from) return;
int height = to - from;
for (int i = 0; i <= height; i++) {
for (int j = 0; j < height-i; j++)
System.out.print(' ');
for (int j = 0; j < (i+1)*2-1; j++)
System.out.print((char)(from + i));
System.out.println();
}
}
}
public static void main(String args[]){
char[] cha = {'A', 'B', 'C', 'D', 'E'};
print(cha);
}
public static void print(char[] cha){
int len = cha.length;
for (int i = 0; i < len; i++) {
for (int j = 1; j < len - i; j++) {
System.out.print(" ");
}
for (int j = 0; j < 2 *i + 1; j++) {
System.out.print(cha[i]);
}
System.out.println();
}
}
* 字符的大小写转换,A变成a,a变成A.
*
* @param c
* @return
*/
public static char toggle(char c) {
return (char) ((c & 0x20) == 0 ? (c | 0x20) : (c & 0xDF));
}
{
Scanner sc = new Scanner(System.in);
String s = sc.next();
System.out.println("小写:"+s.toLowerCase());
System.out.println("大写:"+s.toUpperCase());
}
第二题:public class Triangle {
public static void main(String[] args) {
triangle('A', 'C');
}
public static void triangle(char from, char to) {
if (to < from) return;
int height = to - from;
for (int i = 0; i <= height; i++) {
for (int j = 0; j < height-i; j++)
System.out.print(' ');
for (int j = 0; j < (i+1)*2-1; j++)
System.out.print((char)(from + i));
System.out.println();
}
}
}
Java code /**
* 字符的大小写转换,A变成a,a变成A.
*
* @param c
* @return
*/
public static char toggle(char c) {
return (char) ((c & 0x20) == 0 ? (c | 0x20) : (c & 0xDF));
}
这个比较爽啊。