日常の練習
2416 ワード
class Test00
{
public static void test01(){
System.out.println('a');//a
System.out.println('a'+1);//98 --- , --->
System.out.println("hello"+'a'+1);//helloa1 --->
System.out.println('a'+1+"hello");//98hello ---> ,
System.out.println("5+5="+5+5);//5+5=55
System.out.println(5+5+"=5+5");//10=5+5
}
public static void main(String[] args){
test01();
}
}
class Test01
{
public static void main(String[] args){
int num1 = 10;
int num2 = 20;
//1、
int max = num1 > num2 ? num1 : num2;
System.out.println("max = " + max);
//2、if else
int max2;
if(num1 > num2){
max2 = num1;
} else {
max2 = num2;
}
System.out.println("max2 = "+max2);
//--------------- ------------------------
int num3 = 10;
int num4 = 100;
int num5 = 50;
//1、
//
int max3 = num3 > num4 ? num3 : num4;
//
int max4 = max3 > num5 ? max3 : num5;
System.out.println("max4 = " + max4);
// :
int max5 = num3 > num4 ? (num3 > num5 ? num3 : num5) : (num4 > num5 ? num4 : num5);
System.out.println("max5 = " + max5);
//---------- ---------------------------
int num6 = 10;
int num7 = 20;
boolean isEquals = num6 == num7;
System.out.println("isEquals = " + isEquals);
}
}
/**
: ---
:
: ---
: true false --- boolean
*/
class Test02
{
public static int max(int num1,int num2){
//int result = num1 > num2 ? num1 : num2;
//return result;
// :
return num1 > num2 ? num1 : num2;
}
public static boolean isEquals(int num1, int num2){
//boolean isEquals = num1 == num2;
//return isEquals;
// :
return num1 == num2;
}
public static void main(String[] args){
int max = max(3,4);
System.out.println("max = " + max);
boolean isEquals = isEquals(4,4);
System.out.println("isEquals = " + isEquals);
}
}
/**
, ,
*/
import java.util.Scanner;
class Test03
{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println(" :");
int num1 = scanner.nextInt();
System.out.println(" ");
int num2 = scanner.nextInt();
int sum = num1 + num2;
System.out.println(num1 + " + " + num2 + " = " + sum);
}
}