1/17
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No study sessions yet.
System.out.println();Outputs the text followed by a — moves to the next line.
System.out.print();Outputs the text without adding a newline, meaning the next output will continue on the same line.
System.out.println();
System.out.print();Output Operations
public class Main{
public static void main(String[] args){
System.out.print("wiw umaga na. ");
System.out.println("ows taalaga ba");
System.out.println("imissu<3");
}
}OUTPUT:
wiw umaga na. ows taalaga ba
imissu<3
Example of output operations
%d
%f
%s
%n
Common format specifiers
%d
Integer
%f
Floating point number
%s
String
%n
Newline
public class Main{
public static void main(String[] args){
int eyj = 19;
double grade = 89.56;
String misij = "unsint a misij";
System.out.printf("age %d years", eyj);
System.out.printf("grade: %.3f gew \n", grade);
System.out.printf("misij: %s hihi %n", misij);
System.out.print("yihi");
}
}OUTPUT:
age 19 yearsgrade: 89.560 gew
misij: unsint a misij hihi
yihi
Example of output operations using different format specifiers.
java.util package
To read input, you first need to import the Scanner class from the ________.
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner scanner = new Scanner (System.in);
}
}Example code of the Using Scanner.
nextInt()
nextDouble()
nextLine()
next()
Common input methods of scanner
nextInt()
Reads an integer.
nextDouble()
Reads a double value.
nextLine()
Reads a string line.
next()
Reads a single word up to the next whitespace.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter your full name: ");
String name = sc.nextLine();
System.out.print("Enter your Section: ");
String section = sc.nextLine();
System.out.print("Enter your age: ");
int age = sc.nextInt();
System.out.print("Enter you 1st sem GWA: ");
double gwa = sc.nextDouble();
System.out.println();
System.out.println("Name: " + name);
System.out.println("Section: " + section);
System.out.println("Age: " + age);
System.out.println("1st Sem General Weighted Average: " + gwa);
}
}OUTPUT:
Enter your full name: Jes
Enter your Section: CS12S4
Enter your age: 19
Enter you 1st sem GWA: 1.81
Name: Jes
Section: CS12S4
Age: 19
1st Sem General Weighted Average: 1.81
Example of scanner input