SP23 BSE 022 - Labtask
SP23 BSE 022 - Labtask
LAIBA ZAHOOR
SP23-BSE-022
Task-1:
import java.util.Scanner;
int zeroes = 0;
System.out.println("Now enter the actual numbers: ");
Task-4:
import java.util.Scanner;
while(true)
{
Task-5:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int max = Integer.MIN_VALUE; // Initialize max to the smallest possible integer
while (true) {
int num = scanner.nextInt();
if (num == 0) {
break; // End the loop when 0 is encountered
}
if (max != Integer.MIN_VALUE) {
System.out.println("The largest element is: " + max);
} else {
System.out.println("No numbers were entered.");
}
}
}
Task-6:
import java.util.Scanner;
while (true) {
int num = scanner.nextInt();
if (num == 0) {
break; // End the loop when 0 is encountered
}
if (index != -1) {
System.out.println("Index of the largest element is: " + index);
} else {
System.out.println("No numbers were entered.");
}
}
}
Task-7:
import java.util.Scanner;
if (num % 2 == 0) {
evenCount++; // Increment the even count if the current number is even
}
}
Task-8:
import java.util.Scanner;
while (true) {
int num = scanner.nextInt();
if (num == 0) {
break; // End the loop when 0 is encountered
}
b).
public class Main {
public static void main(String[] args) {
int rows = 5; // Change the number of rows as needed
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
c).
public class Main {
public static void main(String[] args) {
int rows = 5; // Change the number of rows as needed
// Print asterisks
for (int k = 1; k <= i; k++) {
System.out.print("*");
}
System.out.println();
}
}
}
d).
public class Main {
public static void main(String[] args) {
int rows = 5; // Change the number of rows as needed
// Print asterisks
for (int k = 1; k <= 2 * i - 1; k++) {
System.out.print("*");
}
System.out.println();
}
}
}
e).
public class Main {
public static void main(String[] args) {
int rows = 5; // Change the number of rows as needed
// Print numbers
for (int k = 1; k <= 2 * i - 1; k++) {
System.out.print(i);
}
System.out.println();
}
}
}
Task-10: import java.util.Scanner;