paiza skill check standard input / output summary [Java edition]

I'll put them together to solve the problem that the input and output that stumble first in the paiza skill check are not what you want.

One string

str

import java.util.*;

public class Main {
    public static void main(String[] args) {
        /*Reading input value*/
        Scanner sc = new Scanner(System.in);
        
        /*Get str*/
        String str = sc.nextLine();

        /*Output processing*/
        System.out.println(str);
    }
}

One integer

n

import java.util.*;

public class Main {
    public static void main(String[] args) {
        /*Reading input value*/
        Scanner sc = new Scanner(System.in);
        
        /*Get str*/
        String n_s = sc.nextLine();
        int n = Integer.parseInt(n_s); //Convert to integer type

        /*Output processing*/
        System.out.println(n);
    }
}

n integers

n n1 n2 n3 ...

import java.util.*;

public class Main {
    public static void main(String[] args) {
        /*Reading input value*/
        Scanner sc = new Scanner(System.in);

        /*Get n*/
        String n_s = sc.nextLine();
        int n = Integer.parseInt(n_s); //Convert to integer type

        /* n1 n2 n3 ...Get*/
        //Divide into an array for each element with a character type separated by spaces
        String[] datas_s = sc.nextLine().split(" ");
        //Convert element to integer type
        int[] datas = new int[datas_s.length];
        for(int i = 0; i < datas_s.length; i++){
            datas[i] = Integer.parseInt(datas_s[i]);
        }

        /*Output processing*/
        System.out.println(n);
        System.out.println(Arrays.toString(datas));
    }
}

n-line integer

n 1n1 1n2 1n3 2n1 2n2 2n3 3n1 3n2 3n3 ...

import java.util.*;

public class Main {
    public static void main(String[] args) {
        /*Reading input value*/
        Scanner sc = new Scanner(System.in);
        
        /*Get*/
        String n_s = sc.nextLine();
        int n = Integer.parseInt(n_s); //Convert to integer type
        
        /*Output processing*/
        System.out.println(n);
        
        /*Get*/
        int[][] datas = new int[10][10]; //Rewrite according to the number of data
        
        for(int i = 0; i < n; i++){
            //Divide into an array for each element by character type
            String[] datas_s = sc.nextLine().split(" ");
            //Convert element to integer type
            for(int j = 0; j < datas_s.length; j++){
                datas[i][j] = Integer.parseInt(datas_s[j]);
            }
            
            /*Output processing*/
            System.out.println(Arrays.toString(datas[i]));
        }
        
    }
}

Recommended Posts

paiza skill check standard input / output summary [Java edition]
[Java] How to get and output standard input
I tried Java Lambda input / output type ~ POJO edition ~
Java standard log output sample
[Java] I want to test standard input & standard output with JUnit
[Java] Paiza's skill check is clogged with D if you can not master standard input
I tried the input / output type of Java Lambda ~ Map edition ~
AtCoder 400 points algorithm summary (Java edition)
Story of paiza.jp [Java standard input solution]
[Java] Color the standard output to the terminal
Try to carry out paiza skill check
From terminal to Ruby (standard input / output)
Let's write Java file input / output with NIO
[Swift] Template for receiving standard input of Paiza
Effective Java 2nd Edition Related Matters Survey Summary