0% found this document useful (0 votes)
10 views9 pages

FA24-BCS-045 PF_2

The document contains a programming assignment for Muhammad Abdullah Riaz, detailing various Java programs to be implemented. These programs include functionalities such as grade assignment based on marks, checking if a number is even or odd, finding the largest of three numbers, printing multiplication tables, summing even numbers, and displaying shapes using loops. Each program is accompanied by its Java code implementation.

Uploaded by

85abdullahmalik
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)
10 views9 pages

FA24-BCS-045 PF_2

The document contains a programming assignment for Muhammad Abdullah Riaz, detailing various Java programs to be implemented. These programs include functionalities such as grade assignment based on marks, checking if a number is even or odd, finding the largest of three numbers, printing multiplication tables, summing even numbers, and displaying shapes using loops. Each program is accompanied by its Java code implementation.

Uploaded by

85abdullahmalik
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
You are on page 1/ 9

ASSIGNMENT NO 1

NAME: MUHAMMAD ABDULLAH RIAZ

ROLL NO: FA24-BCS-045

SECTION: BCS-2-A

SUBJECT: PROGRAMMING FUNDAMENTALS

SUBMITTED TO: SIR FAYEZ


a)Write a Java program that takes student marks (0-100) as input. Use IF-ELSE statements to assign a
grade:

A (85-100) B (70-84) C (55-69) D (40-54) F (Below 40)


The program should display the student’s grade.

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.print("Enter student marks: ");
int marks = scanner.nextInt();
int grade;
if( marks>=85 && marks<100){
System.out.println("GRADE IS A");
} else if (marks>=70 && marks<=84) {
System.out.println("GRADE IS B");
} else if (marks>=55 && marks<=69) {
System.out.println("GRADE IS C");
}
else if (marks>=40 && marks<=54) {
System.out.println("GRADE IS D");
}
else if (marks>=0 && marks<=40) {
System.out.println("YOU ARE FAIL");
}
else { System.out.println("ENTER VALID MARKS") }

}
Write a Java program that checks whether a given integer is even or odd using an IF-ELSE statement.

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int a= 44;
if (a%2==0){
System.out.println(a+" is an even number");
}
else {
System.out.println(a+" is an odd number");
}

}
}
Create a Java program that takes three numbers as input and determines the largest number using
nested IF-ELSE statements

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.println("enter number 1: ");
int num1=scanner.nextInt();
System.out.println("enter number 2: ");
int num2=scanner.nextInt();
System.out.println("enter number 3: ");
int num3=scanner.nextInt();
if(num1>num2)
if(num1>num3){
System.out.println(num1+" is the largest number ");
}
else {
System.out.println(num3+" is the largest number");
}
else
if(num2>num3){
System.out.println(num2+" is the largest number ");
}
else {
System.out.println(num3+" is the largest number");
}}
Write a Java program that takes an integer N (1-10) as input and uses a FOR loop to print the
multiplication table of N (from 1 to 10).
1. import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.println("ENTER AN INTEGER: ");
int n= scanner.nextInt();
System.out.println("Multiplication table of "+n );
for (int i=1;i<=10;i++){
System.out.println(n+" x "+i +" = " +(n * i));
}
}
}
Develop a Java program that takes an integer X and prints all numbers from 1 to X using a WHILE loop.

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
System.out.println("Enter an integer: ");
int X= scanner.nextInt();
int i=1;
while (i<=X){
System.out.println(i);
i++;
}

}
}
Write a Java program that calculates the sum of all even numbers from 1 to 100 using a FOR loop.

public class Main {


public static void main(String[] args) {

int sum=0;
for(int i=2;i<=100;i+=2){
sum +=i;
System.out.println("Sum of even numbers between 1 to 100 is "+sum);
}

}
}
Construct a program that displays the following shape using nested for loops.

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int rows = 4;
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= rows - i; j++) {
System.out.print(" ");
}
for (int k = 1; k <= (2 * i - 1); k++) {
System.out.print("*");
}
System.out.println();
}
}
}
Construct a program that displays the following shape using nested for loops.
2. public class Main {
public static void main(String[] args) {
int n = 5;

for (int i = 1; i <= n; i++) {


for (int j = i; j < n; j++) {
System.out.print(" ");
}
for (int k = 1; k <= (2 * i - 1); k++) {
System.out.print("*");
}
System.out.println();
}
for (int i = n - 1; i >= 1; i--) {
for (int j = n; j > i; j--) {
System.out.print(" ");
}
for (int k = 1; k <= (2 * i - 1); k++) {
System.out.print("*");
}
System.out.println();
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy