Commit eeecca47 authored by Arsam Ali's avatar Arsam Ali

Loop Assesment

parent 48c876a5
package Upskills_Training.Loops;
import java.util.Scanner;
public class Pyramids {
public static void main(String[] args) {
//Shadow
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of rows for the pyramid: ");
int rows = scanner.nextInt();
for (int i = 0; i < rows; i++) {
// Print leading spaces
for (int j = rows - i; j > 1; j--) {
System.out.print(" ");
}
// Print stars with hollow spaces
for (int j = 0; j <= 2 * i; j++) {
System.out.print("*");
}
System.out.println();
}
for (int i = rows - 1; i >= 0; i--) {
// Print leading spaces
for (int j = rows - i; j > 1; j--) {
System.out.print(" ");
}
// Print stars
for (int j = 0; j <= 2 * i; j++) {
System.out.print("*");
}
System.out.println();
}
//J Vertical Tiles
// int rows = 7;
// for (int a = 0; a <= 5; a++) {
// for (int i = 1; i <= rows; i++) {
// for (int j = 1; j <= rows - i; j++) {
// System.out.print(" ");
// }
// for (int k = 1; k <= i * 2; k++) {
// if (k % 2 == 1) {
// System.out.print("*");
// } else {
// System.out.print(" ");
// }
// }
// System.out.println();
// }
//I Horizontal Tiles
// int rows = 7;
// int diamondInSameLine = 5;
// for (int i = 1; i <= rows; i++) {
// for (int d = 0; d < diamondInSameLine; d++) {
// for (int j = 1; j <= rows - i; j++) {
// System.out.print(" ");
// }
// for (int j = 1; j <= i * 2; j++) {
// if (j % 2 == 1) {
// System.out.print("*");
// } else {
// System.out.print(" ");
// }
// }
// int equalGap = rows - i;
// for (int z = 1; z <= equalGap; z++) {
// System.out.print(" ");
// }
// }
// System.out.println();
// }
// }
// }
//}
}
}
package Upskills_Training.Loops;
import java.util.Scanner;
public class QS_13_VolumeOfCubic {
public static void main(String[] args) {
System.out.println("Enter the height");
Scanner scanner = new Scanner(System.in);
int Height = scanner.nextInt();
System.out.println("Enter the width");
int width = scanner.nextInt();
System.out.println("Enter the depth");
int depth = scanner.nextInt();
int volume = Height * width * depth;
if (volume >= 1 && volume <= 10) {
System.out.println("Extra Small");
} else if (volume >= 11 && volume <= 25) {
System.out.println("Small");
} else if (volume >= 26 && volume <= 75) {
System.out.println("Medium");
} else if (volume >= 76 && volume <= 100) {
System.out.println("Large");
} else if (volume >= 101 && volume <= 250) {
System.out.println("Extra Large");
} else {
System.out.println("Extra-Extra Large");
}
}
}
\ No newline at end of file
package Upskills_Training.Loops;
import java.util.Scanner;
public class QS_1_ImtiazStoreDiscount {
public static void main(String[] args) {
System.out.println("WELCOME TO IMTIAZ STORE :)");
System.out.println("Enter your First Product");
Scanner scanner = new Scanner(System.in);
int product1 = scanner.nextInt();
System.out.println("Enter your Second Product");
int product2 = scanner.nextInt();
System.out.println("Enter your Third Product");
int product3 = scanner.nextInt();
int totalBill = product1 + product2 + product3;
for (int i = 0; i == 0; i++) {
if (totalBill >= 5000) {
System.out.println("Congrats you get a discount of 10% for shopping of 5000 :)");
}
}
System.out.println("Your total bill is " + totalBill);
}
//using do while but not run completely
// System.out.println("WELCOME TO IMTIAZ STORE :) ");
//
// Scanner scanner = new Scanner(System.in);
// System.out.println("Enter your First Product");
// int item1 = scanner.nextInt();
//
// System.out.println("Enter your Second Product");
// int item2 = scanner.nextInt();
//
// System.out.println("Enter your Third Product");
// int item3 = scanner.nextInt();
//
// int totalBill = item1 + item2 + item3;
//
// boolean discountOn = false;
//
// do {
// if (totalBill==5000)
// {
// System.out.println("Congrats, you get a discount of 10% :)");
// discountOn = true;
// }
// }
// while (!discountOn);
//
// System.out.println("You have bought the products successfully. Total bill is " + totalBill);
// scanner.close();
}
package Upskills_Training.Loops;
import java.util.Scanner;
public class QS_2_EmployeeGrossSalary {
static double grossSalary;
public static void main(String[] args) {
System.out.println("Enter Employee Salary");
Scanner scanner = new Scanner(System.in);
double salary = scanner.nextDouble();
if (salary < 15000)
{
double homeRental = salary/10;
double diningAllowance = salary/100*90;
grossSalary = salary + homeRental + diningAllowance;
System.out.println("Home Rental Allowance is " + homeRental + " which is from basic salary " + " and Dining allowance is " + diningAllowance + " which is 90% of basic salary");
System.out.println("Gross Salary is " + grossSalary);
}
if(salary>=15000 && salary < 20000)
{
double homeRental = salary/10;
double diningAllowance = salary/100*98;
grossSalary = salary + homeRental + diningAllowance;
System.out.println("home Rental Allowance is now Rs. 500 and DiningAllowance is now " + diningAllowance );
System.out.println("Total gross Salary is " + grossSalary);
}
}
}
package Upskills_Training.Loops;
import java.util.Scanner;
public class QS_3_NascentInnovationCompany {
static String gender;
static int age;
public static void main(String[] args) {
System.out.println("Welcome To NAscent Innovation");
System.out.println("Please Enter your Marital Status");
Scanner scanner = new Scanner(System.in);
String maritalStatus = scanner.nextLine();
if (maritalStatus.equalsIgnoreCase("Married")) {
System.out.println("You are Insured");
}
if (maritalStatus.equalsIgnoreCase("unmarried")) {
System.out.println("Enter your gender");
gender = scanner.nextLine();
System.out.println("Age your age");
age = scanner.nextInt();
if (gender.equalsIgnoreCase("male") && age > 28)
{
System.out.println("You are Insured");
} else if (gender.equalsIgnoreCase("female") && age > 22) {
System.out.println("You are Insured");
}
else {
System.out.println("You are not insured");
}
}
}
}
package Upskills_Training.Loops;
import java.util.Scanner;
public class QS_4_MatrixMultiplication {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Matrix Multiplication");
System.out.println("Enter first Matrix elements");
int rows1 = scanner.nextInt();
int column1 = scanner.nextInt();
System.out.println("Enter Second Matrix elements");
int rows2 = scanner.nextInt();
int column2 = scanner.nextInt();
if (column1!=rows2)
{
System.out.println("Matrix multiplication is not possible");
}
int[][] matrix1 = new int[rows1][column1];
int [][] matrix2 = new int[rows2][column2];
int[][] result = new int[column1][rows2];
System.out.println("Enter the element First of matrix");
for (int i=0; i< rows1; i++)
{
for (int j=0; j< column1; j++)
{
matrix1[i][j] = scanner.nextInt();
}
}
System.out.println("Enter the element of Second matrix");
for (int i=0; i< rows2; i++)
{
for (int j=0; j< column2; j++)
{
matrix2[i][j] = scanner.nextInt();
}
}
System.out.println("Resultant Matrix :");
for (int i=0; i<rows1; i++)
{
for (int j= 0; j<column2; j++)
{
result[i][j] = matrix1[i][j] * matrix2[i][j];
}
}
for (int[] val: result) {
for (int finalResult:val) {
System.out.print(" "+finalResult);
}
System.out.println();
}
}
}
package Upskills_Training.Loops;
import java.util.Scanner;
public class QS_4_MirrorImageArray {
public static void main(String[] args) {
String arrayOne = "originalArray";
String arrayTwo = "secondArray";
System.out.println("Enter your 2D Array Dimensions");
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the Rows");
int row = scanner.nextInt();
System.out.println("Enter the Column");
int column = scanner.nextInt();
String[][] array = new String[row][column];
for (int i = 0; i < row; i++) {
for (int j = 0; j < column; j++) {
array[i][j] = scanner.next();
}
}
System.out.println("The array is:" + arrayOne);
for (int i = 0; i < row; i++) {
for (int j = 0; j < column; j++) {
System.out.print(array[i][j] + " ");
}
System.out.println();
}
System.out.println("The Flipped Array is : " + arrayTwo);
for (int i = 0; i < row; i++) {
for (int j = column - 1; j >= 0; j--) {
System.out.print(array[i][j] + " ");
}
System.out.println();
}
}
}
package Upskills_Training.Loops;
import java.util.Scanner;
public class QS_4_NumbersNature {
public static void main(String[] args) {
System.out.println("Enter your Number");
Scanner scanner = new Scanner(System.in);
double inputValue = scanner.nextDouble();
if (inputValue <= 0) {
if (inputValue % 2 == 0) {
System.out.println("Its Negative Even Number");
} else {
System.out.println("Its Negative Odd Number");
}
} else {
if (inputValue % 2 == 0) {
System.out.println("Its Positive Even Number");
} else {
System.out.println("Its Positive Odd Number");
}
}
}
}
package Upskills_Training.Loops;
import java.util.Scanner;
public class QS_4b_SecretPin {
public static void main(String[] args) {
System.out.println("Enter your secret pin");
Scanner scanner = new Scanner(System.in);
final int secretPin = 1234;
boolean correctPin = false;
int counter=0;
while (counter<3){
counter++;
int enteredPin = scanner.nextInt();
if(enteredPin==secretPin)
{
correctPin = true;
break;
}
else
{
System.out.println("Please Re-Try your pin");
}
}
if (correctPin)
{
System.out.println("Access Granted");
}
else
{
System.out.println("Your are blocked after three attempts :) ");
System.exit(0);
}
}
}
package Upskills_Training.Loops;
import java.util.Scanner;
public class QS_4c_SecretPin {
public static void main(String[] args) {
System.out.println("Enter your Secret Pin :");
Scanner scanner = new Scanner(System.in);
final int secretPin = 1234;
boolean correctPin = false;
int counter = 0;
do {
counter++;
int enteredPin = scanner.nextInt();
if (enteredPin == secretPin) {
correctPin = true;
break;
} else {
System.out.println("Please Re-Try your pin :");
}
}
while (counter < 3) ;
if (correctPin) {
System.out.println("Access Granted");
}
else {
System.out.println("You are Blocked after 3 attempts :)");
System.exit(0);
}
}
}
package Upskills_Training.Loops;
import java.util.Scanner;
public class QS_5_CalculateSalary {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your Gender");
String gender = scanner.nextLine();
System.out.println("Enter your Year Of Experience");
int yearOfExperience = scanner.nextInt();
System.out.println("Enter your Qualification");
String qualification = scanner.next();
if (gender.equalsIgnoreCase("male") && yearOfExperience <= 5 && (qualification.equals("MS") || qualification.equals("MBA"))) {
System.out.println("Your Salary is : 90,000");
System.exit(0);
} else if (gender.equalsIgnoreCase("male") && yearOfExperience <= 5 && (qualification.equals("BS") || qualification.equals("MCS"))) {
System.out.println("Your Salary is : 60,000");
} else if (gender.equalsIgnoreCase("male") && yearOfExperience > 5 && (qualification.equals("BS") || qualification.equals("MCS"))) {
System.out.println("Your Salary is : 50,000");
} else if (gender.equalsIgnoreCase("male") && yearOfExperience > 5 && qualification.equals("BBA")) {
System.out.println("Your Salary is : 25,000");
} else if (gender.equalsIgnoreCase("female") && yearOfExperience <= 5 && (qualification.equals("MS") || qualification.equals("MBA"))) {
System.out.println("Your Salary is : 80,000");
} else if (gender.equalsIgnoreCase("female") && yearOfExperience <= 5 && (qualification.equals("BS") || qualification.equals("MCS"))) {
System.out.println("Your Salary is : 55,000");
} else if (gender.equalsIgnoreCase("female") && yearOfExperience < 5 && (qualification.equals("BS") || qualification.equals("MCS"))) {
System.out.println("Your Salary is : 40,000");
} else if (gender.equalsIgnoreCase("female") && yearOfExperience < 5 && qualification.equals("BBA")) {
System.out.println("Your Salary is : 20,000");
}
else
{
System.out.println("Kindly input a correct requirements to see the salary");
}
}
}
package Upskills_Training.Loops;
import java.util.Scanner;
public class QS_5_IncrementalDecrementalLoop {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int startValue = scanner.nextInt();
int endValue = scanner.nextInt();
if (startValue < endValue) {
for (int i = startValue; i <= endValue; i++) {
System.out.println("Your Loop is Running Incremental" + i);
}
System.exit(0);
} else if (startValue > endValue) {
for (int i = startValue; i >= endValue; i--) {
System.out.println("Your Loop is Running Decremental" + i);
}
}
System.exit(0);
}
}
package Upskills_Training.Loop;
import java.util.Objects;
import java.util.Scanner;
public class QS_6_ProfitOrLoss {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your Selling Price");
double sellingPrice = scanner.nextDouble();
System.out.println("Enter your Cost Price");
double costPrice = scanner.nextDouble();
double profit = costPrice - sellingPrice;
double loss = sellingPrice - costPrice;
if (profit > loss) {
System.out.println("Your in profit");
System.out.println("you wants to see how much profit or loss you get ? if yes then press C ");
String input = scanner.next();
if (Objects.equals(input, "C")) {
System.out.println("You get profit value of " + profit);
}
} else if (loss > profit) {
System.out.println("Your in loss");
System.out.println("you wants to see how much profit or loss you get ? if yes then press C ");
String input = scanner.next();
if (Objects.equals(input, "C")) {
System.out.println("You get loss value of " + loss);
} else if (Objects.equals(input, "No")) {
System.out.println("Thanks for Shopping");
}
} else {
System.out.println("Please enter correct values");
}
}
}
package Upskills_Training.Loops;
import java.util.Scanner;
public class QS_6_TableUpTo25 {
public static void main(String[] args) throws InterruptedException {
System.out.println("Enter your Input For Table Generation");
Scanner scanner = new Scanner(System.in);
int inputTableValue = scanner.nextInt();
System.out.println("You have selected the input : " + inputTableValue + " wait your table is generating");
Thread.sleep(2000);
for (int i=1; i<=25; i++)
{
System.out.println(inputTableValue + "*" + i + "=" + inputTableValue*i);
}
}
}
package Upskills_Training.Loops;
import java.util.Scanner;
public class QS_7_AlphaBravoCharlieAge {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter Alpha Age");
int alphaAge = scanner.nextInt();
System.out.println("Enter Bravo Age");
int bravoAge = scanner.nextInt();
System.out.println("Enter Charlie Age");
int charlieAge = scanner.nextInt();
if (alphaAge < bravoAge && alphaAge < charlieAge)
{
System.out.println("Alpha is Youngest");
} else if (bravoAge<alphaAge && bravoAge<charlieAge) {
System.out.println("Bravo is Youngest");
} else if (charlieAge<alphaAge && charlieAge<bravoAge) {
System.out.println("Charlie is Youngest");
}
else
{
System.out.println("Please enter valid Age");
}
}
}
package Upskills_Training.Loops;
import java.util.Scanner;
public class QS_8_2sPower {
public static void main(String[] args) {
System.out.println("Enter your Number for Making its 2's Power");
final int baseComponent = 2;
Scanner scanner = new Scanner(System.in);
int power = scanner.nextInt();
System.out.println("Your Ans is ");
System.out.println(Math.pow(baseComponent,power));
}
}
package Upskills_Training.Loops;
import java.util.Scanner;
public class QS_8_XY_Coordinates {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your X Coordinate");
int xCoordinates = scanner.nextInt();
System.out.println("Enter your Y Coordinate");
int yCoordinates = scanner.nextInt();
if (xCoordinates == 0 && yCoordinates == 0)
{
System.out.println("X and Y Coordinates are on origin : (0,0)");
}
else if(xCoordinates==0 || yCoordinates!=0 )
{
System.out.println("X Coordinate are in origin but Y are " + yCoordinates);
System.out.println("So Coordinates are : " + xCoordinates + " " + yCoordinates);
} else if (yCoordinates==0 || xCoordinates!=0) {
System.out.println("Y Coordinate are in origin but X are " + xCoordinates);
System.out.println("So Coordinates are : " + xCoordinates + " " + yCoordinates);
}
else
{
System.out.println("Your X and Y Coordinates are : " + xCoordinates + " " +yCoordinates);
}
}
}
package Upskills_Training.Loops;
import java.util.Scanner;
public class QS_9_RadiusOfCircle {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your Radius");
double radius = scanner.nextDouble();
System.out.println("Enter your P2 Point");
double p2Point = scanner.nextDouble();
double x = 19;
double y = -1;
if (x >= radius && p2Point >= y) {
System.out.println("you are in circle " + x);
} else {
System.out.println("you are out from circle " + y);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment