package sample03_input;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class MainClass_sample03_input {
public static void main(String[] args)throws Exception {
Scanner sc = new Scanner(System.in);
boolean b;
System.out.print("b = ");
b = sc.nextBoolean();
System.out.println("b:" + b);
int number;
System.out.print("number = ");
number = sc.nextInt();
System.out.println("number :" + number);
double d;
System.out.print("d=");
d = sc.nextDouble();
System.out.println("d:"+ d);
String str;
System.out.print("str = ");
str = sc.next();
System.out.println("str:" + str);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str1;
System.out.print("str1 = ");
str1 = br.readLine();
System.out.println("str1:" + str1);
}
}
Cast
package sample04;
public class MainClass {
public static void main(String[] args) {
short sh;
sh = 128;
int i;
i = sh;
System.out.println("i = " + i);
i = 12345;
sh = (short)i;
System.out.println("sh = " + sh);
int number1, number2;
number1 = 3;
number2 = 2;
float f, f1;
f = (float)number1 / number2;
System.out.println("f = " + f);
}
}
Operator
package sample05;
public class MainCalss {
public static void main(String[] args) {
int num1, num2;
num1 = 7;
num2 = 2;
int result;
result = num1 + num2;
System.out.println(num1 + " + " + num2 + " = " + result );
result = num1 * num2;
System.out.println(num1 + " * " + num2 + " = " + result );
result = num1 / num2;
System.out.println(num1 + " / " + num2 + " = " + result );
result = num1 % num2;
System.out.println(num1 + " % " + num2 + " = " + result );
int money = 13500;
int m = money % 1000;
System.out.println("m = " + m);
int number1;
number1 = 0;
number1++;
System.out.println("number1 = " + number1);
number1--;
int number2;
number2 = 0;
int number3;
number3 = number2++;
System.out.println("number3 = " + number3);
int number_3;
number2 = 0;
number_3 = ++number2;
System.out.println("number_3 = " + number_3);
int number4 = 5;
System.out.println( number4 < 10 );
System.out.println(number4 < 0 && number4 < 10);
System.out.println(number4 < 0 || number4 > 10);
System.out.println( !(number4 < 10) );
System.out.println( number4 = 5 );
System.out.println( number4 == 5 );
System.out.println( number4 != 5 );
int n;
n = (number4 > 0) ? 11 : 22;
System.out.println("n = " + n);
char c;
c = (number4 > 10) ? 'Y' : 'N';
System.out.println("c = " + c);
String s;
s = (number4 > 4) ? "4보다 크다." : "4보다 작다.";
System.out.println("s = " + s);
}
}
Array
package sample05;
public class MainCalss {
public static void main(String[] args) {
int num1, num2;
num1 = 7;
num2 = 2;
int result;
result = num1 + num2;
System.out.println(num1 + " + " + num2 + " = " + result );
result = num1 * num2;
System.out.println(num1 + " * " + num2 + " = " + result );
result = num1 / num2;
System.out.println(num1 + " / " + num2 + " = " + result );
result = num1 % num2;
System.out.println(num1 + " % " + num2 + " = " + result );
int money = 13500;
int m = money % 1000;
System.out.println("m = " + m);
int number1;
number1 = 0;
number1++;
System.out.println("number1 = " + number1);
number1--;
int number2;
number2 = 0;
int number3;
number3 = number2++;
System.out.println("number3 = " + number3);
int number_3;
number2 = 0;
number_3 = ++number2;
System.out.println("number_3 = " + number_3);
int number4 = 5;
System.out.println( number4 < 10 );
System.out.println(number4 < 0 && number4 < 10);
System.out.println(number4 < 0 || number4 > 10);
System.out.println( !(number4 < 10) );
System.out.println( number4 = 5 );
System.out.println( number4 == 5 );
System.out.println( number4 != 5 );
int n;
n = (number4 > 0) ? 11 : 22;
System.out.println("n = " + n);
char c;
c = (number4 > 10) ? 'Y' : 'N';
System.out.println("c = " + c);
String s;
s = (number4 > 4) ? "4보다 크다." : "4보다 작다.";
System.out.println("s = " + s);
}
}
과제
package problem01;
public class MainClass {
public static void main(String[] args) {
System.out.println("================================================================");
System.out.println("\\ name\t\tage\tman\tphone\t\theght\taddress \\");
System.out.println("================================================================");
System.out.println("\\ \"홍길동\"\t20\ttrue\t010-111-2222\t175.12\t\"경기도\" \\");
System.out.println("\\ \"일지매\"\t18\ttrue\t02-123-4567\t180.01\t\"서울\"\t\\");
System.out.println("\\ \"장옥정\"\t14\ttrue\t02-345-7890\t155.78\t\"부산\"\t\\");
System.out.println("================================================================");
}
}
package problem02;
import java.util.Scanner;
public class MainClass_problem02 {
public static void main(String[] args) {
String name1, name2, name3;
name1 = "홍길동";
name2 = "일지매";
name3 = "장옥정";
int age1, age2, age3;
age1 = 20;
age2 = 18;
age3 = 14;
boolean a, b, c;
a = true;
b = true;
c = false;
String phone1, phone2, phone3;
phone1 = "010-111-2222";
phone2 = "02-123-4567";
phone3 = "02-345-7890";
double height1, height2, height3;
height1 = 175.12;
height2 = 180.01;
height3 = 155.78;
String address1, address2, address3;
address1 = "경기도";
address2 = "서울";
address3 = "부산";
System.out.println("================================================================");
System.out.println("\\ name\t\tage\tman\tphone\t\theght address \\");
System.out.println("================================================================");
System.out.printf("\\ \"%s\"\t%s\t%s\t%s\t%s\t\"%s\" \\\n", name1, age1, a, phone1, height1, address1);
System.out.printf("\\ \"%s\"\t%s\t%s\t%s\t%s\t\"%s\"\t\\\n", name2, age2, b, phone2, height2, address2);
System.out.printf("\\ \"%s\"\t%s\t%s\t%s\t%s\t\"%s\"\t\\\n", name3, age3, c, phone3, height3, address3);
System.out.println("================================================================");
}
}
package problem03;
import java.util.Scanner;
public class MainClass_problem03 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String name;
System.out.print("name = ");
name = sc.next();
int age;
System.out.print("age = ");
age = sc.nextInt();
String gender;
System.out.print("What's your gender = ");
gender = sc.next();
String phone;
System.out.print("What's your Phone Number = ");
phone = sc.next();
double height;
System.out.print("Height = ");
height = sc.nextDouble();
String address;
System.out.print("Address = ");
address = sc.next();
System.out.println("================================================================");
System.out.println("Name = " + name);
System.out.println("Age = " + age);
System.out.println("Gender = " + gender);
System.out.println("Phone = " + phone);
System.out.println("Height = " + height);
System.out.println("Adress = " + address);
}
}
package problem03;
import java.util.Scanner;
public class MainClass_problem03 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String name;
System.out.print("name = ");
name = sc.next();
int age;
System.out.print("age = ");
age = sc.nextInt();
String gender;
System.out.print("What's your gender = ");
gender = sc.next();
String phone;
System.out.print("What's your Phone Number = ");
phone = sc.next();
double height;
System.out.print("Height = ");
height = sc.nextDouble();
String address;
System.out.print("Address = ");
address = sc.next();
System.out.println("================================================================");
System.out.println("Name = " + name);
System.out.println("Age = " + age);
System.out.println("Gender = " + gender);
System.out.println("Phone = " + phone);
System.out.println("Height = " + height);
System.out.println("Adress = " + address);
}
}