Practice Program Basic Java

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Practice Program: 1.

Java Code to Print Good Day if time is less than 18hrs or


else Print Good Evening

Code:

public class Main {

public static void main(String[] args) {

int time = 20;

if (time < 18) {

System.out.println("Good day.");

} else {

System.out.println("Good evening.");

Practice Program: 2 Java Code to Print Good Morning if time is less then 10am
or else print Good Day if time is less than 20hrs or else Print Good Evening

public class Main {

public static void main(String[] args) {

int time = 22;

if (time < 10) {

System.out.println("Good morning.");

} else if (time < 20) {

System.out.println("Good day.");

} else {

System.out.println("Good evening.");
}

Practice Program: 3 Java Code to print given text in to Lower Case & Upper
Case

Code:

public class Main {

public static void main(String[] args) {

String txt = "Hello World";

System.out.println(txt.toUpperCase());

System.out.println(txt.toLowerCase());

String Concatenation
The + operator can be used between strings to combine them. This is
called concatenation:

Example
public class Main {
public static void main(String args[]) {
String firstName = "John";
String lastName = "Doe";
System.out.println(firstName + " " + lastName);
}
}

You might also like