By GokiSoft.com| 15:42 05/09/2022|
Java Basic

Java Basic- Kiểm tra số chẵn và lẻ - mệnh đề điều kiên if - else trong java BT976

Nhập số nguyên x, in ra x là số chẵn hay số lẻ

Liên kết rút gọn:

https://gokisoft.com/976

Bình luận

avatar
Nguyen Tri Duc [java1_online]
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);
	}
}


avatar
Trần Nhựt Linh [java1_online]
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");}
    }
}


avatar
le anh tuan [java1_online]
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();  
    }
}


avatar
Nguyễn Viết Nguyên [java1_online]
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);
}
}
}
avatar
Hoàng Anh [C2010G]
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ẻ");
        }
    }
}


avatar
Phạm Đăng Khoa [community,C2010L]
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");
        }
    }
    
}


avatar
Trần Việt Đức Anh [C2010L]
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");
        }
    }
}


avatar
Võ Như Việt [C2010L]
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");

         }

        

    }

}


avatar
hieuvm0512 [community,C2010L]
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");
        }
}
}


avatar
Phạm Ngọc Đại [community,C2010G]
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);

        }

    }

}