import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner reader = new Scanner(System.in); // Reading from System.in
System.out.println("Enter name: ");
String name = reader.nextLine(); // Scans the next token
System.out.println("Enter age: ");
int age = reader.nextInt(); // Scans the next token
System.out.println(name + " is " + age + " years old.");
}
}
int a = 10, b = 10; // Example of initialization
double pi = 3.14159; // declares and assigns a value of PI.
char c = 'a';
String d = "a string";
// For loop
for (int i = 0; i < 10; i++) {
if (i % 2 == 0)
System.out.println(i + " is an even number");
else
System.out.println(i + " is an odd number");
}
int[] numbers = {10, 20, 30, 40, 50};
// Fast enumeration
for (int x : numbers) {
System.out.print(x + ",");
}
// Switch statement
String vegetable = "red pepper";
String vegetableComment;
switch (vegetable) {
case "celery":
vegetableComment = "Add some raisins and make ants on a log.";
break;
case "cucumber":
vegetableComment = "That would make a good tea sandwich.";
break;
default:
vegetableComment = "Everything tastes good in soup.";
break;
}
public class Main {
public static void main(String args[]) {
Employee empOne = new Employee("James Smith");
empOne.empAge(26);
empOne.empDesignation("Senior Software Engineer");
empOne.empSalary(1000);
empOne.printEmployee();
}
}
class Employee {
String name;
int age;
String designation;
double salary;
public Employee(String name) {
this.name = name;
}
public void empAge(int empAge) {
age = empAge;
}
public void empDesignation(String empDesig) {
designation = empDesig;
}
public void empSalary(double empSalary) {
salary = empSalary;
}
public void printEmployee() {
System.out.println("Name:" + name);
System.out.println("Age:" + age);
System.out.println("Designation:" + designation);
System.out.println("Salary:" + salary);
}
}