I want to convert characters ...

I'm doing a competition pro and I've run out of time due to problem A, so take notes

One character can be operated by char type

Convert one character to the next

char c = 'a';
c++;
System.out.println( c ); // b

Case conversion

char c = 'a';
c -= 32;
System.out.println( c ); // A

Convert from lowercase to uppercase -32 Uppercase to lowercase conversion is +32

Other

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

Stumble problem

https://atcoder.jp/contests/abc151/tasks/abc151_a

A - Next Alphabet

Problem statement

Given a lowercase C that is not z. Output the next letter of C in alphabetical order.

Constraint

C is a non-z lowercase letter

Answer

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

Actual answer

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

I want to convert characters ...
I want to convert InputStream to String
I learned stream (I want to convert List to Map <Integer, List>)
Swift: I want to chain arrays
I want to use FormObject well
I want to docker-compose up Next.js!
[Java] I want to convert a byte array to a hexadecimal number
I want to develop a web application!
I want to write a nice build.gradle
I want to eliminate duplicate error messages
I want to convert an array to Active Record Relation with Rails
I want to make an ios.android app
I want to display background-ground-image on heroku.
I want to use DBViewer with Eclipse 2018-12! !!
[Ruby] I want to put an array in a variable. I want to convert to an array
I want to RSpec even at Jest!
I want to write a unit test!
I want to install PHP 7.2 on Ubuntu 20.04.
I want to stop Java updates altogether
I want to use @Autowired in Servlet
I want to target static fields to @Autowired
I want to do team development remotely
[Ruby] I want to output only the odd-numbered characters in the character string
I want to test Action Cable with RSpec test
I want to sort by tab delimited by ruby
I want to output the day of the week
Run R from Java I want to run rJava
[Swift] I want to draw grid lines (squares)
I want to send an email in Java.
I want to graduate from npm install properly [2020]
I want to use arrow notation in Ruby
[Ruby] I want to do a method jump!
I want to use java8 forEach with index
I want to var_dump the contents of the intent
I want to pass APP_HOME to logback in Gradle
I want to simply write a repeating string
I want to design a structured exception handling
rsync4j --I want to touch rsync in Java.
I want to play with Firestore from Rails
[Xcode] I want to manage images in folders
I want to be eventually even in kotlin
I want to write quickly from java to sqlite
I want to truncate after the decimal point
I want to reduce simple mistakes. To command yourself.
I want to perform aggregation processing with spring-batch
[Rails] I want to load CSS with webpacker
[Ruby] When you want to replace multiple characters
I want to delete files managed by Git
I want to get the value in Ruby
I want to use Combine in UIKit as well.
I want to use Clojure's convenient functions in Kotlin
I want to call a method of another class
I want to do something like "cls" in Java
[Java] I want to calculate the difference from the date
I want to use NetBeans on Mac → I can use it!
I want to embed any TraceId in the log
Pointcut Expression I want to specify more than one
I want to use fish shell in Laradock too! !!
Convert the array of errors.full_messages to characters and output
I want to use ES2015 in Java too! → (´ ・ ω ・ `)
I want to judge the range using the monthly degree