0% found this document useful (0 votes)
2 views2 pages

Examples Variables and Data Types Java

The document provides examples of Java programming concepts, including basic variables, data types, user input, type conversion, and boolean logic. Each example demonstrates how to declare variables, perform computations, and handle user authentication. Sample outputs are included to illustrate the results of the code execution.

Uploaded by

ykwlibs
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Examples Variables and Data Types Java

The document provides examples of Java programming concepts, including basic variables, data types, user input, type conversion, and boolean logic. Each example demonstrates how to declare variables, perform computations, and handle user authentication. Sample outputs are included to illustrate the results of the code execution.

Uploaded by

ykwlibs
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Example 1: Basic Variables and Data Types

public class Example1 {


public static void main(String[] args) { Sample Output

int age = 20; Student Name: Juan Dela Cruz


double gradeAverage = 89.75;
String studentName = "Juan Dela Cruz"; Age: 20
boolean isEnrolled = true;
Grade Average: 89.75

[Link]("Student Name: " + studentName); Enrolled: true


[Link]("Age: " + age);
[Link]("Grade Average: " + gradeAverage);
[Link]("Enrolled: " + isEnrolled);
}
}

Example 2: Variables with User Input and Type Conversion

import [Link];
Sample Output
public class Example2 {
public static void main(String[] args) { Enter your name: Maria

Enter your age: 19


Scanner input = new Scanner([Link]);
Enter tuition fee: 15000
[Link]("Enter your name: ");
String name = [Link]();
--- Student Information ---
[Link]("Enter your age: ");
int age = [Link](); Name: Maria

[Link]("Enter tuition fee: "); Age: 19


double tuitionFee = [Link]();
Tuition Fee: 15000.0
boolean isAdult = age >= 18;
Adult: true
[Link]("\n--- Student Information ---");
[Link]("Name: " + name);
[Link]("Age: " + age);
[Link]("Tuition Fee: " + tuitionFee);
[Link]("Adult: " + isAdult);

[Link]();
}
}
Example 3: Variables Used in Computation

public class Example3 {


Units Enrolled: 18
public static void main(String[] args) {
Cost per Unit: 1000.5
int units = 18; Total Tuition: 18009.0
double costPerUnit = 1000.50;

double tuition = units * costPerUnit;

[Link]("Units Enrolled: " + units);


[Link]("Cost per Unit: " + costPerUnit);
[Link]("Total Tuition: " + tuition);
}
}

Example 4: Variables, Strings, and Boolean Logic

import [Link]; Enter username: student01


Enter password: python123
public class Example4 {
public static void main(String[] args) {
Login Status
String username = "student01"; Access Granted: true
String password = "python123";

Scanner input = new Scanner([Link]);


Enter username: Ryan
[Link]("Enter username: "); Enter password: admin
String inputUsername = [Link]();

[Link]("Enter password: "); Login Status


String inputPassword = [Link](); Access Granted: false

boolean isValidUser =
[Link](username) &&
[Link](password);

[Link]("\nLogin Status");
[Link]("Access Granted: " + isValidUser);

[Link]();
}
}

You might also like