Java Basic- Kiểm tra số chẵn và lẻ - mệnh đề điều kiên if - else trong java
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![Nguyen Tri Duc [java1_online]](https://www.gravatar.com/avatar/9ad80c7352fd64a202fbfb45d9ca9fb1.jpg?s=80&d=mm&r=g)
Nguyen Tri Duc
2023-04-15 14:47:42
import java.util.Scanner;
public class KiemTraSoChan_Le {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Nhap so nguyen x: ");
int x = sc.nextInt();
String result = "So le.";
if (x % 2 == 0) {
result = "So chan.";
}
System.out.println(result);
}
}
![Trần Nhựt Linh [java1_online]](https://www.gravatar.com/avatar/6e945f8e29edcd38ec9b7492c0265f02.jpg?s=80&d=mm&r=g)
Trần Nhựt Linh
2023-03-26 05:34:52
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
*/
package com.mycompany.javabasic;
import java.util.Scanner;
/**
*
* @author mymem
*/
public class JavaBasic {
public static void main(String[] args) {
int x;
int y;
Scanner scan = new Scanner(System.in);
System.out.println("Nhap so:");
x = scan.nextInt();
y = x%2;
if(y==0){System.out.println("X la so chan");}
else{System.out.println("x la so le");}
}
}
![le anh tuan [java1_online]](https://www.gravatar.com/avatar/0c79bbaaa43a903799a613fb8a163e0a.jpg?s=80&d=mm&r=g)
le anh tuan
2022-09-01 03:46:20
public class SoChanSole {
public static void checkNumBer(){
Scanner scanner = new Scanner(System.in);
System.out.print("Nhap so nguyen x: ");
int x = scanner.nextInt();
if( x == 0){
System.out.println("x la so 0");
}else if (x % 2 != 0 ){
System.out.println("x la so le");
}else if (x % 2 == 0){
System.out.println("x la so chan");
}
}
public static void main(String[] args){
checkNumBer();
}
}
![Nguyễn Viết Nguyên [java1_online]](https://www.gravatar.com/avatar/ca0f47db043b00fca52a41f529dd9c8a.jpg?s=80&d=mm&r=g)
Nguyễn Viết Nguyên
2022-07-13 10:42:53
import java.util.Scanner;
public class EvenOddNumber {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an integer number:");
int number = scanner.nextInt();
if (number%2==0){
System.out.printf("%d is even number", number);
}else {
System.out.printf("%d is odd number",number);
}
}
}
![Hoàng Anh [C2010G]](https://www.gravatar.com/avatar/e73c31efff649e599b1e4320b6bfb1a9.jpg?s=80&d=mm&r=g)
Hoàng Anh
2022-06-17 13:50:38
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package c2108l;
import java.util.Scanner;
/**
*
* @author Hoàng Anh aka bom1
*/
public class bai3 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Nhập số nguyên x:");
int x = Integer.parseInt(input.nextLine());
if(x %2 == 0){
System.out.println("số nguyên x là số chẵn");
}else{
System.out.println("Số nguyên x là số lẻ");
}
}
}
![Phạm Đăng Khoa [community,C2010L]](https://www.gravatar.com/avatar/c38babdc190b58e31608b8ddefc3ba1a.jpg?s=80&d=mm&r=g)
Phạm Đăng Khoa
2021-07-01 11:15:12
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package main;
import java.util.Scanner;
/**
*
* @author Khoa Pham
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int x;
Scanner scan = new Scanner(System.in);
System.out.println("Nhap so x: ");
x = scan.nextInt();
if(x % 2 == 0){
System.out.println("So "+x+ " la so chan");
} else {
System.out.println("So "+x+" la so le");
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package main;
import java.util.Scanner;
/**
*
* @author Khoa Pham
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int x;
Scanner scan = new Scanner(System.in);
System.out.println("Nhap so x: ");
x = scan.nextInt();
if(x % 2 == 0){
System.out.println("So "+x+ " la so chan");
} else {
System.out.println("So "+x+" la so le");
}
}
}
![Trần Việt Đức Anh [C2010L]](https://www.gravatar.com/avatar/caee507e11365ca2cf5068cbea5c740a.jpg?s=80&d=mm&r=g)
Trần Việt Đức Anh
2021-06-29 17:35:05
/*
Nhập số nguyên x, in ra x là số chẵn hay số lẻ
*/
package Lession1;
import java.util.Scanner;
/**
*
* @author Tran Viet Duc Anh
*/
public class OddAndEvenX {
public static void main(String[] args) {
Scanner n = new Scanner(System.in);
System.out.println("Enter x:");
int x = n.nextInt();
if (x % 2 == 0){
System.out.println("x is the even ");
} else {
System.out.println("x is the odd");
}
}
}
![Võ Như Việt [C2010L]](https://www.gravatar.com/avatar/fb93c99beb23339eb21f4d4ffe8981af.jpg?s=80&d=mm&r=g)
Võ Như Việt
2021-06-29 14:19:49
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package vietvo.full.basic;
import java.util.Scanner;
/**
*
* @author ADMIN
*/
public class KiemSo {
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
Scanner nhapso = new Scanner(System.in);
System.out.println("Nhap x= ");
int x = nhapso.nextInt();
if( x % 2 == 0){
System.out.println("So " + x + " la so chan");
}
else{
System.out.println ("So " + x + " la so le");
}
}
}
![hieuvm0512 [community,C2010L]](https://www.gravatar.com/avatar/0cacbf21fed14b987a433597d2edc14f.jpg?s=80&d=mm&r=g)
hieuvm0512
2021-06-29 13:08:14
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.mycompany.jv1;
import java.util.Scanner;
/**
*
* @author vuive
*/
public class Main {
public static void main(String[] args){
// System.out.println("Hello World");
Scanner input = new Scanner(System.in);
System.out.println("Nhap vao so x");
int x = input.nextInt();
if(x%2 == 0){
System.out.println("x la so chan");
}else{
System.out.println("x la so le");
}
}
}
![Phạm Ngọc Đại [community,C2010G]](https://www.gravatar.com/avatar/a2d762c32047edba0ef5bd2049993b20.jpg?s=80&d=mm&r=g)
Phạm Ngọc Đại
2021-06-28 03:40:03
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Class04;
import java.util.Scanner;
/**
*S
* @author Admin
*/
public class inSoNguyen {
public static void main(String[] args) {
Scanner sn = new Scanner(System.in);
int x = sn.nextInt();
if(x % 2 == 0) {
System.out.println("x la so chan: " + x);
}else {
System.out.println("x la so le: " + x);
}
}
}