(3) - screen output & console input
Screen output
println 줄바꿈
print 다붙여씀
printf : format str + output str
%f - float %d - integer %s - string %e
System.out.print("$");
System.out.printf("%10.4f", 23.788888);
System.out.println("each");
System.out.printf("Start%-8.2fEnd%n", 12.123);
System.out("$%6.2f_%d for each %s.%n", 19.8, 3, "apple");
System.out.printf("%2s%n","zzzzz");
System.out.printf("%7c%n","z");
System.out.printf("%12.5e", 123456.1234567);
//$___23.7889each
Start12.12___End
$_19.80_3 for each apple.
zzzzz
______z
__1.2346e+05
M.Nf => M자리차지 N소수점아래
string은 생략 안함
e 디폴트: 1.123456e+0n 소수점6개
System.out
Class system
an object used for sending output to the screen
println
method that System.out object performs
Money Formats
import java.text.NumberFormat
getCurrencyInstance(나라, 디폴트는 현재나라);
import java.text.NumberFormat;
import java.util.Locale;
NumberFormat moneyFormater = NumberFormat.getCurrencyInstance();
System.out.println(moneyFormater.format(23.5));
NumberFormat dollarFormater = NumberFormat.getCurrencyInstance(Locale.US);
System.out.println(dollarFormater.format(23.5));
Packages
libraries in Java
collections of classes
java.lang 은 자동import됨
import java.text.NumberFormat
impott java.text.* // text 전부 import
console input
import java.util.Scanner;
Scanner scannerObject = new Scanner(System.in);
Scanner scannerObj2 = new Scanner(System.in);
keyboard2.useDelimiter("##"); //scannerObj2에는 delimiter 부여, space는 delimiter 아님
int n1;
n1 = scannerObject.nextInt(); //21
double d1;
d1 = scannerObject.newDouble(); //2.1
String word1 = scannerObject.next(); //apple
String line = scannerObject.nextLine(); // sentence
int numm = scannerObj.nextInt();
String junk = scannerObj.nextLine();
String s1 = scannerObj.nextLine();
String s2 = scannerObj.nextLine();
String
String junk2 = scannerObj.nextLine();
String word1 = scannerObj2.next();
String word2 = scannerObj2.next();
//input: aa bb##cc dd##
//word1 : aa bb
//word2 : cc dd
import java.util.Scanner;
Scanner scannerObject = new Scanner(System.in);
Scanner scannerObj2 = new Scanner(System.in);
keyboard2.useDelimiter("##"); //scannerObj2에는 delimiter 부여, space는 delimiter 아님
int n1;
n1 = scannerObject.nextInt(); //21
double d1;
d1 = scannerObject.newDouble(); //2.1
String word1 = scannerObject.next(); //apple
String line = scannerObject.nextLine(); // sentence
int numm = scannerObj.nextInt();
String junk = scannerObj.nextLine();
String s1 = scannerObj.nextLine();
String s2 = scannerObj.nextLine();
String
String junk2 = scannerObj.nextLine();
String word1 = scannerObj2.next();
String word2 = scannerObj2.next();
//input: aa bb##cc dd##
//word1 : aa bb
//word2 : cc dd
in interactive program,
print prompt recommended before user input
& always echo all input!
Author And Source
이 문제에 관하여((3) - screen output & console input), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@yungommi/Java3저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)