By GokiSoft.com| 16:12 12/06/2023|
Java Basic

[Share Code] Tìm hiểu biến, toán tử, nhập scanner và mệnh đề điều kiên - C2209I

/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.gokisoft.c2209i;

import java.util.Scanner;

/**
 *
 * @author teacher
 */
public class Test02 {

    static enum LIGHT_STATUS {
        ON, OFF
    };

    static enum STUDENT_STATUS {
        PENDING, APPROVED, LEARNING, DROPOUT
    };

    public static void main(String[] args) {
        System.out.println("Xin chao");
        int x = 5;
        int k = 6, t = 10;
        float x1;
        x1 = 60.5F;

        System.out.println("x = " + x + ", k = " + k);

        System.out.format("\nx = %d, k = %d, x1 = %f\n", x, k, x1);

        char c = 'A';
        System.out.println("c = " + c);

        String str = "SINH VIEN APTECH 54 LE THANH NGHI";
        System.out.println(str);

        final int u = 10;
        System.out.println("u = " + u);

        //Kieu du lieu enum
        //LIGHT -> Status: ON (SANG), OFF (Tat)
        boolean status = true;//true: sang, false: tat
        int status2 = 1;//1: Sang, 0: Tat

        LIGHT_STATUS status3 = LIGHT_STATUS.ON;
        status3 = LIGHT_STATUS.OFF;

        //Nhap du lieu tu ban phim
        int t1;
        String s1;

        //B1. Khai bao doi tuong ban phim -> Cho phep nhap du lieu
        Scanner tenbien = new Scanner(System.in);
        
        System.out.println("Nhap t1 = ");
//        t1 = tenbien.nextInt();
//        tenbien.nextLine() -> Nhap du lieu tu ban phim -> 1 bien: x
//        Integer.parseInt(x) -> Chuyen String x -> ve so nguyen
//        Integer.parseInt(tenbien.nextLine()) -> Gop lenh -> Viet cho nhanh
        t1 = Integer.parseInt(tenbien.nextLine());
        System.out.println("t1 = " + t1);
        
        System.out.println("Nhap s1: ");
        s1 = tenbien.nextLine();
        System.out.println(s1);
    }
}

Tags:



Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

Đăng nhập để làm bài kiểm tra

Chưa có kết quả nào trước đó