0% found this document useful (0 votes)
122 views

Practice Program Basic Java

The document contains 3 Java code examples and explanations. The first example prints "Good Day" if the time is less than 18 hours and "Good Evening" otherwise. The second improves on this by adding a check for "Good Morning" if the time is before 10am. The third example uses string methods toUpperCase() and toLowerCase() to print a given text in both cases. It also explains string concatenation using the + operator to combine strings.

Uploaded by

jkdprince3
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views

Practice Program Basic Java

The document contains 3 Java code examples and explanations. The first example prints "Good Day" if the time is less than 18 hours and "Good Evening" otherwise. The second improves on this by adding a check for "Good Morning" if the time is before 10am. The third example uses string methods toUpperCase() and toLowerCase() to print a given text in both cases. It also explains string concatenation using the + operator to combine strings.

Uploaded by

jkdprince3
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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