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

Java Tasks Before Eid (1)

The document contains four Java programming tasks demonstrating basic concepts. Task 1 covers variable declaration and output, Task 2 focuses on user input and formatted output, Task 3 implements if-else conditions for number evaluation, and Task 4 showcases loops with natural numbers and countdowns. Each task is presented with code examples illustrating the respective concepts.

Uploaded by

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

Java Tasks Before Eid (1)

The document contains four Java programming tasks demonstrating basic concepts. Task 1 covers variable declaration and output, Task 2 focuses on user input and formatted output, Task 3 implements if-else conditions for number evaluation, and Task 4 showcases loops with natural numbers and countdowns. Each task is presented with code examples illustrating the respective concepts.

Uploaded by

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

******** Task 1: Variables & Data Types ********

public class Task1 {


public static void main(String[] args) {
// Declaring variables
String studentName = "Hamis Ali";
int rollNumber = 101;
double percentage = 88.5;
char grade = 'A';

// Printing all values


System.out.println("Student Name: " + studentName);
System.out.println("Roll Number: " + rollNumber);
System.out.println("Percentage: " + percentage + "%");
System.out.println("Grade: " + grade);
}
}

******** Task 2: Input/Output ********


import java.util.Scanner;

public class Task2 {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);

// Taking user input


System.out.print("Enter your full name: ");
String fullName = input.nextLine();

System.out.print("Enter your age: ");


int age = input.nextInt();

input.nextLine(); // Clear buffer

System.out.print("Enter your city: ");


String city = input.nextLine();

// Displaying formatted output


System.out.println("Hello " + fullName + ", you are " + age + " years old
and live in " + city + ".");
}
}

******** Task 3: If-Else Condition ********


import java.util.Scanner;

public class Task3 {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);

// Input number
System.out.print("Enter a number: ");
int number = input.nextInt();

// Checking condition
if (number > 0) {
System.out.println("The number is positive.");
} else if (number < 0) {
System.out.println("The number is negative.");
} else {
System.out.println("The number is zero.");
}
}
}

******** Task 4: Loops ********


public class Task4 {
public static void main(String[] args) {

// For loop: First 10 natural numbers


System.out.println("First 10 Natural Numbers:");
for (int i = 1; i <= 10; i++) {
System.out.print(i + " ");
}

// While loop: Numbers from 10 to 1


System.out.println("\n\nCountdown from 10 to 1:");
int j = 10;
while (j >= 1) {
System.out.print(j + " ");
j--;
}
}
}

You might also like