I'm doing a competition pro and I've run out of time due to problem A, so take notes
char c = 'a';
c++;
System.out.println( c ); // b
char c = 'a';
c -= 32;
System.out.println( c ); // A
Convert from lowercase to uppercase -32 Uppercase to lowercase conversion is +32
If you calculate on the argument, the character code will be output, so it may be better to add one line quietly
char c = 'a';
System.out.println( c - 32 ); // 65
System.out.println( (char)( c - 32 ) ); //A: OK if you cast
https://atcoder.jp/contests/abc151/tasks/abc151_a
A - Next Alphabet
Given a lowercase C that is not z. Output the next letter of C in alphabetical order.
C is a non-z lowercase letter
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
char c = in.nextLine().charAt(0);
System.out.println( ++c );
}
}
Clean
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String c = in.nextLine();
String base = "abcdefghijklmnopqrstuvwxyz";
for( int i = 0 ; i < base.length() ; i++ ){
if( c.charAt(0) == base.charAt( i ) ){
System.out.println( base.charAt( i + 1 ) );
return;
}
}
}
}
????????????????????? Well, well, well, I'm not wrong It's AC
Recommended Posts