From 6a3c0aa7d82aef0bbf1faa52a1f18ddbc2dd8497 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Sat, 11 Oct 2025 22:32:46 +0000 Subject: [PATCH 1/6] Setting up GitHub Classroom Feedback From 3dbc6296e8f7f4e6568a4ee132f8977d9c901230 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Sat, 11 Oct 2025 22:32:49 +0000 Subject: [PATCH 2/6] add deadline --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 064f0ae..7eb64d3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/ty2f_0nx) # Java-Task1 — Introductory Java Exercises This repository contains three beginner-friendly Java exercises built around the following topics: From 86fafd2b96cbcb70f474bbaf27b4b289164bb7b0 Mon Sep 17 00:00:00 2001 From: Daksh Singh Date: Mon, 13 Oct 2025 00:30:56 +0530 Subject: [PATCH 3/6] question 1 done --- q1/README.md | 3 ++- q1/q1.class | Bin 0 -> 1498 bytes q1/q1.java | 56 ++++++++++++++++++--------------------------------- 3 files changed, 22 insertions(+), 37 deletions(-) create mode 100644 q1/q1.class diff --git a/q1/README.md b/q1/README.md index f4b81b2..a84c6e8 100644 --- a/q1/README.md +++ b/q1/README.md @@ -3,6 +3,7 @@ ## Objective Complete the fill-in-the-blanks exercise in `q1.java` to demonstrate understanding of: + - Basic Java program structure - Variable declarations and initialization - Data types (int, double, char, boolean, String) @@ -74,4 +75,4 @@ java q1 - [ ] All variables are properly declared and initialized - [ ] Output matches the expected format exactly - [ ] Proper use of Java naming conventions -- [ ] All "FILL HERE" comments are replaced with appropriate code \ No newline at end of file +- [ ] All "FILL HERE" comments are replaced with appropriate code diff --git a/q1/q1.class b/q1/q1.class new file mode 100644 index 0000000000000000000000000000000000000000..0998d249c5db1ff1952c625b0d1e927516ee64ac GIT binary patch literal 1498 zcmaJ>-EtC16#kk3GaxZYOd`ggaW^XXhcOy8Bx)qakj3aqDwcZHffmLrMmBH z(I#cpAzKrbz`m;r&pcP^s`dnL7j0x1rk9qMoT~2Bh15=2zENJAYgb8!_LDe{2@8`c zOyLB>_z)uu)~+$xlH?^9x(Tj9K3v%-=C?9*;gcy$;}pYGo9~E{k~OYhxVlM_uesDd z!-ZkGhs|ZcaK;!rYuuId!w?aiGl)M7Vr3{|1TzM4-XKat5m8(;h@3&Z8iKHKi2_NQ z+^ulUoz4AS@oV;MT%nxthHzZpQEwbgm<5M&W#bw{wkh03QxBZgRcE^;Y+PrUY9&k)(0Wr&tkT`-JQTq!m>?QP+0 za&k@wZSGPrCv&e4CpW*vkgTeXR}-tQ0b6^s*GyMX?>$sX``Y8XPlRr&x<3}j{Ujb> z*}_AU%M!!P&n|c6JGCPUVN_v9tn!*x-af;p{$A(-L!)b4)?31#sVKG6*)1Lpuy1ET z(bQ)My#I>f+!gza-7`_*tyb05f(GUhU3r62yWlVzk7-Dk8=+igNUQ}F4UYbzA$@Er z7_6Q!jF$a_DWffhR9Q;lm0H~Qg>T^*!}&wW8Fpt2&#Cc#52die1mPTR(K}OH>NIgiJa*{|*k=+L?hrM{Kokkw#RAC&`W+*%h<{9H7mvd#r=u@L_U zM>5C$#W?Y7yo)RlE~dNWpeN_La1P{&XcvF}Sj4)xaInbaL(R3b-g&v>n@j2o@ z<6Vb&ToM#vl43kUe+ox2O1o*C#4%hXX%6GKPw!X-6L^Ue;1s7zr+d_r`#6R76zd0^ pAsa=q6~Q9C&Y+lMxJMaS3FvA-*8;j8& Date: Mon, 13 Oct 2025 00:41:43 +0530 Subject: [PATCH 4/6] Question 2 done --- q2/README.md | 14 +++++++++++--- q2/q2.class | Bin 0 -> 2524 bytes q2/q2.java | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 q2/q2.class diff --git a/q2/README.md b/q2/README.md index d62df78..164fbc9 100644 --- a/q2/README.md +++ b/q2/README.md @@ -3,8 +3,9 @@ ## Objective Write a complete Java program that demonstrates: + - Getting user input using Scanner -- Arithmetic operators (+, -, *, /, %) +- Arithmetic operators (+, -, \*, /, %) - Relational operators (>, <, >=, <=, ==, !=) - Logical operators (&&, ||, !) - Basic expressions and calculations @@ -28,7 +29,7 @@ Your program should: 6. **Perform** and display the following calculations: - Addition (num1 + num2) - Subtraction (num1 - num2) - - Multiplication (num1 * num2) + - Multiplication (num1 \* num2) - Division (num1 / num2) - Modulus (num1 % num2) - only if both numbers are integers 7. **Demonstrate** relational operators by comparing the two numbers @@ -37,12 +38,14 @@ Your program should: ## Sample Input/Output **Input:** + ``` Enter first number: 15 Enter second number: 4 ``` **Expected Output:** + ``` === Calculator Results === First Number: 15.0 @@ -72,20 +75,24 @@ Modulus: 15 % 4 = 3 ## Implementation Hints 1. **Scanner Setup:** + ```java Scanner scanner = new Scanner(System.in); ``` 2. **Reading Input:** + ```java System.out.print("Enter first number: "); double num1 = scanner.nextDouble(); ``` 3. **Modulus Operation:** + - Convert doubles to integers for modulus: `(int)num1 % (int)num2` 4. **Formatting Output:** + - Use `System.out.println()` for formatted output - Show operations in the format: `operand1 operator operand2 = result` @@ -117,6 +124,7 @@ java q2 ## Additional Challenge (Optional) If you finish early, try adding: + - Input validation (handle invalid input) - Division by zero checking -- More complex expressions combining multiple operators \ No newline at end of file +- More complex expressions combining multiple operators diff --git a/q2/q2.class b/q2/q2.class new file mode 100644 index 0000000000000000000000000000000000000000..bb57c7acca6d49c8a12df2767ead7ccf02cd7dd9 GIT binary patch literal 2524 zcmaJ@%~umw6#qREGQ%(`1|vbM4izu~B~&X#0SgkXX+fy5ShZinWWZ;5B1zmR2eHT5_`(83QNMw@Sncw~0ci(;Y-uEVdya;{+ zFoCZWv>+xSuA&tQhK?Khs-ClTXDK(gc*8V&hQzq#SpF%7SSGt5L1x$~jB37R=Zc2z zIA*mC3fd*8Dz;(!1~0{1o^O^JS}cblH6un^Zm!@|YJSnLntFLmfrJh||4xQr>0stu?Z#9@Z6 zvc7CiyN;pzm&g}AdA{!W9x<7GKA){;GP;5!7zUD5aS|~u;&_WYJIaR?3WX*^WW2p8 z^b4jf!qx59g`T8pj&RTK)PuRw#B&k}j3g7`7FC-B_O0E5csF9JN#vQ)-l=TdNx8S&KJ{v~qNaHy-Vg z)2{1#epRo`n*MdStQY;PZuoBX7Q@46 zvo;LtPS5F1$u_;-8P{E|RmL{2B%;|c@ZznC*~C1$!20I?NHMyHl`N@JvzaZRA{2D;ABMjXW?$QuHVhtL*~8nMn&Kag=x z2rIljgyXE%->=alr?SFPwa(ErS?$gp&T%hwj?NdgC!!%(;HT)ct$Uv7N%)eXZ&T@; zRa63%fB)8|bb{B*j~={7d!Jt|bP&*aPqIL0AKe+A`2%U*O=)1~?JtsP`HA>7Gf)>1zbY0#VIU zfFm0<%K?TqYTN+1bB{C!~%z=lQ=+#X;&#L0>Ec_@Zd z;t|wTdl*T8cSAcOIWIkioKjx$rz3ny3D*-~TIi`Ld0x^MQPSJkPtPejKfBP0G<~}1 zZMFyf^iCY2KA0r_0uG==+Ewb8dpL;4=*1KC@uJ~(9KxUUM*0f__?ynCf9X9W;|NP* zh-HvtqZnrAaE#5>G@*Cm3ZvQFdl&=6}%n0uLlevDhU04=Q`TT*KE;B%Bw< zOk8M{&>f>|jaz8o0ag4@#R?o9*fZxcn+ES9)n=x+h$Me0AKqyh`r wjw0=&%R*ii@>3x{7g86}5YiNKNk~h`Wg*K#x7mB6L4H?p6SvX*Kfw " + num2 + ": " + greater); + System.out.println(num1 + " < " + num2 + ": " + less); + System.out.println(num1 + " >= " + num2 + ": " + greaterEqual); + System.out.println(num1 + " <= " + num2 + ": " + lessEqual); + System.out.println(num1 + " == " + num2 + ": " + equal); + System.out.println(num1 + " != " + num2 + ": " + notEqual); + + // Logical Operations + System.out.println("\n=== Logical Operations ==="); + System.out.println("(" + num1 + " > " + num2 + ") && (" + num1 + " != " + num2 + "): " + (greater && notEqual)); + System.out.println("(" + num1 + " < " + num2 + ") || (" + num1 + " == " + num2 + "): " + (less || equal)); + System.out.println("!(" + num1 + " == " + num2 + "): " + (!equal)); + + input.close(); + } + +} \ No newline at end of file From 8297acfc39b2c135a3a0de18a10812b26fa77870 Mon Sep 17 00:00:00 2001 From: Daksh Singh Date: Mon, 13 Oct 2025 00:48:59 +0530 Subject: [PATCH 5/6] question 3 done --- q3/q3.class | Bin 0 -> 3228 bytes q3/q3.java | 137 +++++++++++++++++++--------------------------------- 2 files changed, 49 insertions(+), 88 deletions(-) create mode 100644 q3/q3.class diff --git a/q3/q3.class b/q3/q3.class new file mode 100644 index 0000000000000000000000000000000000000000..8b4974094203adae1890645524ad26c0a0f4a748 GIT binary patch literal 3228 zcmaJ@-BTOa75`ljl8}WF3u^=hd|iJ@fK2?gF~T^2FhveF#Q395+Qw^Xfwfn=c(o!X z{chZ(`K;ZviCfow?M&b5>9jLD{m4uoI@6i{1D)whAN$ss_N5PL&%LV!6f{|le!J)1 z-#Pc}IrpADfBDq^1As|9O`rv>F+`GRLzE$PN8ixLEZtrmTfBY8D0vLgbEa*2=NVcv z+3W3yqdkU15_^zrpf7J$J)=S_r$$QZf;410V@s}Sd&{0{=#_~$_A+EACnxzuT81x} zp5f|NmFsqyFRs(G=eSiqYg8Ogq(lNKbj6?~(TyI4?j|M~V(Vf7%ceCm!J^W8TG6yu zC$iV$*vBv^)?CtEkDthIFB>kTP$<$#^r4@jx1!%Q3XWaUy&I;tMo(2wx4o(`U(D`a zKmkKqp&$~pA|08U|IeSIQ*D1tyc>D+L_q{!5QYy4^|_|%Z8#zrM+IZHDI3P=g)5}+U*#|yMYwih^+=d-$}^Q)Wd z26tBYh5PHSQLUPk7qLg8QxQrYU6B_)0qJ)OGd(z>Kozi07@TJ~wr%iqe#<*PU9CDL zQ}@gb)7up06!hYvh{%hS)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ivwP4QD4!Y^n){2E8`J7n+)S@|nQ@OO;jpE!>H zQV$lx3D!%U)?wVq&sXzHMF0sE+3-T{4vVY?W`xIAOqPW)5OXr~#FVj1=;1ztC?ms85 zze4AvB+-z#D$$g9S7Jq?Bk`WZs>GVa*CcLA{F=mXNc@(>??`+@;`b!JCGl;E?@D}M a;twP~lK7#-ALC>4F+u)4ra1l#eg6m5-~2ED literal 0 HcmV?d00001 diff --git a/q3/q3.java b/q3/q3.java index b77541b..c99a4ed 100644 --- a/q3/q3.java +++ b/q3/q3.java @@ -1,126 +1,87 @@ // q3.java - Literals, Increment/Decrement Operators, and Expressions Demo // Complete the fill-in-the-blanks to demonstrate various Java concepts - public class q3 { public static void main(String[] args) { System.out.println("=== Java Literals and Operators Demo ===\n"); - + // Part 1: Different types of literals System.out.println("=== Part 1: Literals Demo ==="); - - // FILL HERE: Create an integer literal variable 'decimal' with value 42 - int decimal = 0; // Replace 0 with correct value - - // FILL HERE: Create a binary literal variable 'binary' with value 0b101010 (which is 42 in decimal) - int binary = 0; // Replace 0 with correct binary literal - - // FILL HERE: Create an octal literal variable 'octal' with value 052 (which is 42 in decimal) - int octal = 0; // Replace 0 with correct octal literal - - // FILL HERE: Create a hexadecimal literal variable 'hex' with value 0x2A (which is 42 in decimal) - int hex = 0; // Replace 0 with correct hexadecimal literal - + + int decimal = 42; + int binary = 0b101010; + int octal = 052; + int hex = 0x2A; + System.out.println("Decimal literal: " + decimal); System.out.println("Binary literal: " + binary); System.out.println("Octal literal: " + octal); System.out.println("Hexadecimal literal: " + hex); - - // FILL HERE: Create a float literal variable 'floatNum' with value 3.14f - float floatNum = 0.0f; // Replace with correct value - - // FILL HERE: Create a double literal variable 'doubleNum' with value 2.718281828 - double doubleNum = 0.0; // Replace with correct value - + + float floatNum = 3.14f; + double doubleNum = 2.718281828; + System.out.println("Float literal: " + floatNum); System.out.println("Double literal: " + doubleNum); - - // FILL HERE: Create a char literal variable 'letter' with value 'A' - char letter = ' '; // Replace with correct character - - // FILL HERE: Create a char literal variable 'unicodeChar' with value '\u0041' (which is 'A') - char unicodeChar = ' '; // Replace with correct unicode character - + + char letter = 'A'; + char unicodeChar = '\u0041'; + System.out.println("Character literal: " + letter); System.out.println("Unicode character: " + unicodeChar); - - // FILL HERE: Create a boolean literal variable 'isTrue' with value true - boolean isTrue = false; // Replace with correct value - - // FILL HERE: Create a String literal variable 'message' with value "Hello, Java!" - String message = ""; // Replace with correct string - + + boolean isTrue = true; + String message = "Hello, Java!"; + System.out.println("Boolean literal: " + isTrue); System.out.println("String literal: " + message); - + System.out.println("\n=== Part 2: Increment/Decrement Operators ==="); - - // FILL HERE: Create an integer variable 'counter' with initial value 10 - int counter = 0; // Replace with correct initial value - + + int counter = 10; System.out.println("Initial counter value: " + counter); - - // FILL HERE: Use post-increment (counter++) in the println statement - System.out.println("Post-increment (counter++): " + counter); // Add post-increment operation + + System.out.println("Post-increment (counter++): " + counter++); System.out.println("Counter after post-increment: " + counter); - - // FILL HERE: Use pre-increment (++counter) in the println statement - System.out.println("Pre-increment (++counter): " + counter); // Add pre-increment operation + + System.out.println("Pre-increment (++counter): " + ++counter); System.out.println("Counter after pre-increment: " + counter); - - // FILL HERE: Use post-decrement (counter--) in the println statement - System.out.println("Post-decrement (counter--): " + counter); // Add post-decrement operation + + System.out.println("Post-decrement (counter--): " + counter--); System.out.println("Counter after post-decrement: " + counter); - - // FILL HERE: Use pre-decrement (--counter) in the println statement - System.out.println("Pre-decrement (--counter): " + counter); // Add pre-decrement operation + + System.out.println("Pre-decrement (--counter): " + --counter); System.out.println("Counter after pre-decrement: " + counter); - + System.out.println("\n=== Part 3: Data Type of Expressions ==="); - - // Variables for expression demonstrations + int intVar = 5; double doubleVar = 2.5; float floatVar = 1.5f; char charVar = 'B'; - - // Expression 1: int + int - // FILL HERE: Create a variable 'result1' that stores intVar + 3 (determine the correct data type) - int result1 = 0; // Replace with correct expression and fix data type if needed - + + int result1 = intVar + 3; + double result2 = intVar + doubleVar; + double result3 = floatVar + doubleVar; + int result4 = charVar + intVar; + System.out.println("int + int = " + result1 + " (Type: int)"); - - // Expression 2: int + double - // FILL HERE: Create a variable 'result2' that stores intVar + doubleVar (determine the correct data type) - double result2 = 0.0; // Replace with correct expression and fix data type if needed - System.out.println("int + double = " + result2 + " (Type: double)"); - - // Expression 3: float + double - // FILL HERE: Create a variable 'result3' that stores floatVar + doubleVar (determine the correct data type) - double result3 = 0.0; // Replace with correct expression and fix data type if needed - System.out.println("float + double = " + result3 + " (Type: double)"); - - // Expression 4: char + int - // FILL HERE: Create a variable 'result4' that stores charVar + intVar (determine the correct data type) - int result4 = 0; // Replace with correct expression and fix data type if needed - System.out.println("char + int = " + result4 + " (Type: int, 'B' has ASCII value 66)"); - + System.out.println("\n=== Part 4: Operator Associativity ==="); - - // Demonstrate left-to-right associativity with subtraction + int a = 20, b = 10, c = 5; - // FILL HERE: Calculate result5 = a - b - c (should be evaluated as (a - b) - c) - int result5 = 0; // Replace with correct expression - + int result5 = a - b - c; + System.out.println("Left-to-right: " + a + " - " + b + " - " + c + " = " + result5); - System.out.println("Evaluation: (" + a + " - " + b + ") - " + c + " = " + (a - b) + " - " + c + " = " + result5); - - // FILL HERE: Demonstrate right-to-left associativity with assignment - int x = 0, y = 0, z = 0; // Replace this line with chained assignment x = y = z = 15 - + System.out + .println("Evaluation: (" + a + " - " + b + ") - " + c + " = " + (a - b) + " - " + c + " = " + result5); + + int x, y, z; + x = y = z = 15; + System.out.println("Right-to-left assignment: x = y = z = 15"); System.out.println("x = " + x + ", y = " + y + ", z = " + z); } -} \ No newline at end of file +} From 4d35bf5ac4933a941de80de7eeeaf88d7c5c3451 Mon Sep 17 00:00:00 2001 From: Daksh Singh Date: Mon, 13 Oct 2025 00:50:22 +0530 Subject: [PATCH 6/6] Final check done --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7eb64d3..200dd7d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ [![Review Assignment Due Date](https://classroom.github.com/assets/deadline-readme-button-22041afd0340ce965d47ae6ef1cefeee28c7c493a6346c4f15d667ab976d596c.svg)](https://classroom.github.com/a/ty2f_0nx) + # Java-Task1 — Introductory Java Exercises This repository contains three beginner-friendly Java exercises built around the following topics: @@ -82,4 +83,4 @@ java q3 - Basic understanding of command line/terminal usage - Text editor (VSCode Recommended) or IDE (IntelliJ IDEA recommended) -Proceed to the `q1/`, `q2/`, and `q3/` folders and complete the exercises in order. \ No newline at end of file +Proceed to the `q1/`, `q2/`, and `q3/` folders and complete the exercises in order.