String.charAt (specified position);
public class Main {
public static void main(String[] args){
String str = "Mofumofuneko";
System.out.println(str.charAt(0)); //Also
System.out.println(str.charAt(3)); //Fu
System.out.println(str.charAt(4)); //Ne
System.out.println(str.charAt(5)); //This
}
}
//Numerical comparison
public class Main {
public static void main(String[] args){
System.out.println("1 = 1 ? : " + (1 == 1)); //1 = 1 ? : true
System.out.println("1 = 2 ? : " + (1 == 2)); //1 = 2 ? : false
}
}
//Indicates the branch direction with an if statement
int a = 0;
int b = 1;
if(a == b) {
System.out.println("Run if true");
}
else {
System.out.println("Execute if false");
}
public class Main {
public static void main(String[] args){
//Declare a boolean variable
boolean isEighteen = false;
int Age = 18;
isEighteen = (Age >= 18);
System.out.println(isEighteen); //true
if (isEighteen) { // true
System.out.println("18 years and over"); //18 years and over
} else {
System.out.println("Under 18");
}
}
}
//Determine whether to continue the loop with a while statement
import java.util.Scanner;
public class Main {
public static void main(String[] args){
int i = 0;
while(i < 10) {
System.out.print(i + " ");
i += 1;
}
}
}
Boolean
public class Main {
public static void main(String[] args){
Boolean bool = Boolean.valueOf(true);
System.out.println(bool); //true
bool = null;
System.out.println(bool); //null
}
}
public class Main {
public static void main(String[] args){
Boolean bool = Boolean.valueOf(true);
System.out.println(bool.toString()); //true
}
}
When Taro tries to play cards with Hanako, he has only n cards, which should be 52. Create a program that takes these n cards as input and outputs the missing cards. Taro's first playing card was 52 cards, excluding the Joker. The 52 cards are divided into 4 patterns: spades, hearts, clubs, and diamonds, and each pattern has 13 ranks.
import java.util.*;
class Main {
static char[] symbol = new char[] {'S','H','C','D'};
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
boolean[][] cards = new boolean[4][13];
for(int i = 0; i < n; i++) {
char k = sc.next().charAt(0);
int r = sc.nextInt();
//Note that the array starts at 0!
if(k == 'S') {
cards[0][r-1] = true;
}
if(k == 'H') {
cards[1][r-1] = true;
}
if(k == 'C') {
cards[2][r-1] = true;
}
if(k == 'D') {
cards[3][r-1] = true;
}
}
for(int i = 0 ; i< 4; i++) {
for(int j = 0; j < 13; j++) {
if(!cards[i][j]) {
System.out.println( symbol[i] + " " + (j+1));
}
}
}
}
}