Assignment 1
Assignment 1
Write the program and compile the code @command line to execute to
greet your friends.
CODE:
System.out.println("2022503023");
System.out.println("Hello,3023")
System.out.println("Hello,3023");
Exercise 3: Conversation
Write a Java program to create a Conversation between Java and
Python Java: Hi, I'm Java. What's your name?
Python: I'm Python. Nice to meet you!
Java: Programmers use me for large-scale systems and performance
critical applications.
Python: I'm best for rapid development and scripting
tasks. Java: I use static typing for early error detection.
Python: I use dynamic typing for more flexibility.
Java: I run on the JVM, making me portable across many platforms.
Python: I'm portable with the Python interpreter on any
system. Java: Ideal for enterprise applications and Android
apps. Python: Perfect for web development and data analysis.
Java: My performance is strong with JVM optimizations.
Python: I excel in ease of use and quick development cycles.
Java: Use me for performance and large projects.
Python: Use me for ease and speed in
development. Java: This was great!. Bye for now!
Python: Bye!
CODE:
import java.util.Scanner;
String string;
while(true)
string = sc.nextLine();
if(string.equalsIgnoreCase("Bye"))
break;
if(python.equalsIgnoreCase("Bye"))
break;
}
System.out.println("PYTHON : " +python);
Constraint
year1000
Input: 2024
Output: True
Input: 2025
Output:
False
Also find the next leap year
CODE:
import java.util.Scanner;
int s = sc.nextInt();
if (s < 1000) {
sc.close();
return;
} else {
{
if (s % 400 == 0) {
return true;
} else if (s % 100 == 0) {
return false;
} else if (s % 4 == 0) {
return true;
} else {
return false;
while(!IsLeapyear(nextyear))
nextyear++;
return nextyear;
CODE:
import java.util.Scanner;
int m = scanner.nextInt();
int y = scanner.nextInt();
if (m < 3) {
m += 12;
y -= 1;
switch (dayOfWeek) {
CODE:
public class Flag {
public static void straight()
{
System.out.println("- ".repeat(20));
}
public static void ver()
{
String s = "|";
System.out.printf("%-38s%s\n",s,s);
}
public static void ver2()
{
String s = "|";
String a = "*";
System.out.printf("%-15s********%16s\n",s,s);
}
public static void var1()
{
String s = "|";
System.out.println("|");
}
public static void main(String[] args) {
straight();
for(int i=0;i<2;i++)
{
ver();
}
straight();
for (int i=0;i<=2;i++)
{
ver2();
}
straight();
for (int i=0;i<2;i++)
{
ver();
}
straight();
for(int i=0;i<=7;i++)
{
var1();
}
}
}
OUTPUT:
Write a program to model the AND gate using the linear combination
of
inputs formula
Y=Bias +W0X1+W1X2
where X1 and X2 are the input values, and y is the output, determine
the
values for the weights W0 and W1, and the bias term that will
correctly
model the behavior of a logical AND gate. Use the condition that
Y>0.5
CODE:
import java.util.Scanner;
class OR {
System.out.println("Bias:"+Bias);
for( x1=0;x1<2;x1++)
if (y <= 0.5) {
y=0;
}
else {
y = 1;
Orgate(w0, w1);
OUTPUT:
Exercise 8: Write a program that converts a given integer into its
range of 0 to 999.
Input : 123
CODE:
import java.util.Scanner;
while (true) {
int n = scan.nextInt();
if (n > 999) {
continue;
System.out.printf("%s\n", one_place[n]);
n = n / 10;
System.out.printf("%s\n", temp);
temp+=ten[n];
System.out.println(temp);
n = n % 10;
temp += teen[n];
System.out.printf("%s\n", temp);
} else {
int te = n % 100;
temp+=one_place[te];
te = te / 10;
temp += tei;
tei+=ten[te];
temp+=tei;
te = te % 10;
tei += teen[te];
temp += tei;
System.out.println(temp);
Write a Java program to simulate a simple Casino game where the player
starts
with 1000 credit points. Each roll costs 100 credits (the bet amount). For
each roll,
If the sum of the two dice is 7 or 11, the player wins and gains 100 credits
or If the
sum of the dice is 2, 3, or 12, the player loses 100 credits or For any other
sum (4,
either goes bankrupt (reaches 0 credits) or reaches the target win amount
of 2000
credits.
CODE:
import java.util.*;
int player=1000;
while(true){
int n1 = ran.nextInt(6)+1;
int n2 = ran.nextInt(6)+1;
int n3=n1+n2;
System.out.println("Dice sum:"+n3);
System.out.println("Current Credits:"+player);
if(n1+n2 == 7 || n1+n2 == 11){
player=player+100;
player=player-100;
break;
break;
}
OUTPUT: