Basic Input and Output Operation

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/17

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

18 Terms

1
New cards
System.out.println();

Outputs the text followed by a moves to the next line.

2
New cards
System.out.print();

Outputs the text without adding a newline, meaning the next output will continue on the same line.

3
New cards
System.out.println();
System.out.print();

Output Operations

4
New cards
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

5
New cards

%d
%f
%s
%n

Common format specifiers

6
New cards

%d

Integer

7
New cards

%f

Floating point number

8
New cards

%s

String

9
New cards

%n

Newline

10
New cards
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.

11
New cards

java.util package

To read input, you first need to import the Scanner class from the ________.

12
New cards
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.

13
New cards

nextInt()
nextDouble()
nextLine()
next()

Common input methods of scanner

14
New cards

nextInt()

Reads an integer.

15
New cards

nextDouble()

Reads a double value.

16
New cards

nextLine()

Reads a string line.

17
New cards

next()

Reads a single word up to the next whitespace.

18
New cards
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