From 2b27ddac82621996ee65fd2cf5f9bb3173de4a67 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Sat, 11 Oct 2025 17:28:55 +0000 Subject: [PATCH 1/4] Setting up GitHub Classroom Feedback From c11ef75c5b0dd6cb8c74f3aa2a1221e965eba748 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Sat, 11 Oct 2025 17:28:58 +0000 Subject: [PATCH 2/4] 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 c394046fe1eacb10812d35772749e7b919dbd13f Mon Sep 17 00:00:00 2001 From: Rahilbhoot Date: Sun, 12 Oct 2025 15:37:06 +0530 Subject: [PATCH 3/4] solved all three questions --- q3/q3.class | Bin 0 -> 3241 bytes q3/q3.java | 138 ++++++++++++++++++++++++---------------------------- 2 files changed, 63 insertions(+), 75 deletions(-) create mode 100644 q3/q3.class diff --git a/q3/q3.class b/q3/q3.class new file mode 100644 index 0000000000000000000000000000000000000000..67ebcb0960aa0b574f8b3d69c66ccada6d92c0b8 GIT binary patch literal 3241 zcmaJ@+jCn-8UL*s_fP)~eh1(R-jAUJoe_lM=t5W^ao^lBrySGWn7VfFzE$uA!k28<_Ad)` zrqZ{%5k+?du{e4VZ=tVkSADBQEU!jN`ie4SdsC|w+x6G{ie;8&qUaMy&(6-uXUL6Q zv3;vzI#p@9MR~1EZQrX@<)T&cB#~k$DHUAIj~8ZAXKj$w=l43*3WR?c$^rhnV^H>p+iP1moo`Fwi6 z0}TR6jTV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Mte39$f~CSkZIz$cr6c8+6>8F6OC16*hh z=<&yK5y04$1AM9}&=8X^Hf0v3cZJ9C{{_hI$^mAY0u3?wQd4GOwkc?rDVV6yJBYdI zK5gM*BC%i`(0jvo4UNOo0^}4`?|nVlSC}54&g4LVMb$Z!c#AuA?$iT%V)BaVq<+^J zV(p;-OFNF9=2;IKNt*d^)ELo|`fyPnDH?~ENrFD2(}v}n{6<%u#Um?fq|+GfG{!oO z@kIX}WBiUWW{i@)c8!d)ol$*E9}n=H;_jx=-*~Agndm`FPmmsZI>hO{&`YJ;N4uXu zn%*QA=t(h8BUkA;ah*nQBZ(q09#Z1eC}FlSj@Kyh-hspu%8no7D1JtX@k^Y*Z;--= zlmdUIE&nS{W+uhPx`25yTdcu~AhSM$&58vXzU@mpBpkJu1@!KU~JZ1GPx;y);LMBsJwque1W z(oQ^2^X$M2c#*z8#R%S}qWP@CmlT=`3kofT8wzcO4-}RZdI}#ZtSYQ2{Jg?#gk8jc_@=_Q6n+Okq!?oq-@CMyKf&<-0mViH^#A|> literal 0 HcmV?d00001 diff --git a/q3/q3.java b/q3/q3.java index b77541b..5636762 100644 --- a/q3/q3.java +++ b/q3/q3.java @@ -4,122 +4,110 @@ 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; // Replace 0 with correct value + int binary = 0b101010; // Replace 0 with correct binary literal + int octal = 052; // Replace 0 with correct octal literal + int hex = 0x2A; // Replace 0 with correct hexadecimal literal + 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; // Replace with correct value + double doubleNum = 2.718281828; // Replace with correct value + 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'; // Replace with correct character + char unicodeChar = '\u0041'; // Replace with correct unicode character + 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; // Replace with correct value + String message = "Hello, Java!"; // Replace with correct string + 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; // Replace with correct initial value + 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++); // Add post-increment operation 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 + + // FILL HERE: Use pre-increment (++counter) in the println statement + System.out.println("Pre-increment (++counter): " + ++counter); // Add pre-increment operation 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--); // Add post-decrement operation 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); // Add pre-decrement operation 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 - + // FILL HERE: Create a variable 'result1' that stores intVar + 3 (determine the + // correct data type) + int result1 = intVar + 3; // Replace with correct expression and fix data type if needed + 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 - + + // Expression 2: int + double + // FILL HERE: Create a variable 'result2' that stores intVar + doubleVar + // (determine the correct data type) + double result2 = intVar + doubleVar; // 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 - + // FILL HERE: Create a variable 'result3' that stores floatVar + doubleVar + // (determine the correct data type) + double result3 = floatVar + doubleVar; // 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 - + // FILL HERE: Create a variable 'result4' that stores charVar + intVar + // (determine the correct data type) + int result4 = charVar + intVar; // 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; // Replace with correct expression + System.out.println("Left-to-right: " + a + " - " + b + " - " + c + " = " + result5); - System.out.println("Evaluation: (" + a + " - " + b + ") - " + c + " = " + (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 - + x = y = z = 15; + System.out.println("Right-to-left assignment: x = y = z = 15"); System.out.println("x = " + x + ", y = " + y + ", z = " + z); } From 0d1a0d460a29bd7166271af0517e8c8174e63139 Mon Sep 17 00:00:00 2001 From: Rahilbhoot Date: Sun, 12 Oct 2025 15:38:01 +0530 Subject: [PATCH 4/4] solved q1 and q2 --- q1/q1.class | Bin 0 -> 1918 bytes q1/q1.java | 60 ++++++++++++++++++---------------------------------- q2/q2.class | Bin 0 -> 2802 bytes q2/q2.java | 47 +++++++++++++++++++++++++++++++++++++++- 4 files changed, 67 insertions(+), 40 deletions(-) create mode 100644 q1/q1.class create mode 100644 q2/q2.class diff --git a/q1/q1.class b/q1/q1.class new file mode 100644 index 0000000000000000000000000000000000000000..bbaa213114d8adf553baa61d4f7167cb2e637581 GIT binary patch literal 1918 zcmaJ?-Bwyh6#fR0g9Ia@_?xDrH4)M_)Y{rqG>L&2F+|g1O_TI*gb|J&&cVarT0TQx zptpU5_QJTh$OEMB)YUz6I4Z&l7yHb7d+%>%{|)c|Yrg~V1g!`H7%&iwVh|yQ*a1K0 z8H?N1%=X@aC`*RWifNnj0mDEly&HNoxu}0(L>R)GPR&l{9WjI`h7DYgVg#`+meNU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8jO&Fbv8#&Tufr@uwZyRnt79qAb*PhZcmOh$JzL@FaOkGE^+K2kXE{25~Mr zxkz9{#w#KAqE5sKPcye*OBmzWg#i0{TcR??GDvcf;$j;YX^hEujbXnaKW8r+l{V;I znC9qb8TvT$Vtf4Un9g7a#v~M}-_}MM;xl$tXV@`kSbER~SG2N8mUvC${kV7N#@34F zmKeH9o>p0%*Xkl(!aVg$n^1;S$@ZO!UNktWv^F}zyNU+jtZjR)=Vkf$r&Q)!?-rSD12){-zWPe}^cS{4(KILf>%cyH3TKr+zZ( zCe<)>9}V3%3GZn#a%eCT+OAv14RebaY&E;Y1&z-ZK!GYTWCjIz)sn_88cpM1ng zIByAcGE{F1m3lGot_Zb1R88K=0yw7(3@EhZuG}~!5mUz$%92y=-Qz9}B3yNbbbrgB zupJ3FDY)-}t&^pM1vtRm(mV z+B0W1c?o7+Bsb$;592sLV)y__@^9kLME#L{=Y*Y~XH1;ur#M7we*JdS?{4&BFMZB> zpwj1Y82fM<`>8<=V4mU@$#az&<|Yn9!x7v<7CuFOMyL1%2Jt;j-a|UYpK%O-;5h!o zFk={Dee{tzi4$xVqwF$Hu{HXJe2y{pBMNwn`sOcmKgDlIN|=)%#eyIHZ%AJ(_LSH? z=ZFgjdrC~7^ZdWI3_Sn(ouV*pYnEubsA~IOyshKKt}Uk!LHy6>fDT*~9k_r?^eoeT zvPO5wWg$yKzAfZcA+HH}L&$f9d|yaS$cm7 " + num2 + ": " + (num1 > num2)); + System.out.println(num1 + " < " + num2 + ": " + (num1 < num2)); + System.out.println(num1 + " >= " + num2 + ": " + (num1 >= num2)); + System.out.println(num1 + " <= " + num2 + ": " + (num1 <= num2)); + System.out.println(num1 + " == " + num2 + ": " + (num1 == num2)); + System.out.println(num1 + " != " + num2 + ": " + (num1 != num2)); + + System.out.println("\n=== Logical Operations ==="); + System.out.println( + "(" + num1 + " > " + num2 + ") && (" + num1 + " != " + num2 + "):" + ((num1 > num2) && (num1 != num2))); + System.out.println( + "(" + num1 + " < " + num2 + ") || (" + num1 + " == " + num2 + "):" + ((num1 < num2) || (num1 == num2))); + System.out.println("!(" + num1 + " == " + num2 + "): " + (!(num1 == num2))); + } +} \ No newline at end of file