By GokiSoft.com|
21:28 22/06/2022|
Java Basic
[Video] Java Basic- Loop - for, while, do - while >> Quản lý thông tin sinh viên - C2108L
Java Basic- Loop - for, while, do - while >> Quản lý thông tin sinh viên
#Main.java
/*
* 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 bt979;
import java.util.Scanner;
/**
*
* @author DiepTV
*/
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String fullname = null, email = null;
int choose;
do {
showMenu();
choose = Integer.parseInt(input.nextLine());
switch (choose) {
case 1:
System.out.println("Nhap ten: ");
fullname = input.nextLine();
System.out.println("Nhap email: ");
email = input.nextLine();
break;
case 2:
System.out.println("Ten: " + fullname + ", email: " + email);
break;
case 3:
System.out.println("Thoat!!!");
break;
}
} while(choose != 3);
}
public static void showMenu() {
System.out.println("1. Nhap thong tin sinh vien");
System.out.println("2. Hien thi thong tin sinh vien");
System.out.println("3. Thoat chuong trinh");
System.out.println("Chon: ");
}
}
#Test.java
/*
* 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 bt979;
import java.util.Scanner;
/**
*
* @author DiepTV
*/
public class Test {
static String fullname = null, email = null;
static Scanner input = new Scanner(System.in);
public static void main(String[] args) {
int choose;
do {
showMenu();
choose = Integer.parseInt(input.nextLine());
switch (choose) {
case 1:
inputStudent();
break;
case 2:
displayStudent();
break;
case 3:
System.out.println("Thoat!!!");
break;
}
} while(choose != 3);
}
public static void showMenu() {
System.out.println("1. Nhap thong tin sinh vien");
System.out.println("2. Hien thi thong tin sinh vien");
System.out.println("3. Thoat chuong trinh");
System.out.println("Chon: ");
}
private static void inputStudent() {
System.out.println("Nhap ten: ");
fullname = input.nextLine();
System.out.println("Nhap email: ");
email = input.nextLine();
}
private static void displayStudent() {
System.out.println("Ten: " + fullname + ", email: " + email);
}
}
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)