xxxxxxxxxx
// Program to print "Hello, World!" to the console
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
// Program to calculate the sum of two numbers
public class Addition {
public static void main(String[] args) {
int num1 = 5, num2 = 3;
int sum = num1 + num2;
System.out.println("Sum: " + sum);
}
}
// Program to check if a number is prime
public class PrimeCheck {
public static void main(String[] args) {
int num = 17;
boolean isPrime = true;
for (int i = 2; i <= num / 2; ++i) {
if (num % i == 0) {
isPrime = false;
break;
}
}
if (isPrime)
System.out.println(num + " is a prime number.");
else
System.out.println(num + " is not a prime number.");
}
}
// Program to reverse a string
public class StringReverse {
public static void main(String[] args) {
String str = "Hello";
StringBuilder reversed = new StringBuilder();
for (int i = str.length() - 1; i >= 0; --i) {
reversed.append(str.charAt(i));
}
System.out.println("Reversed string: " + reversed.toString());
}
}
xxxxxxxxxx
//Abdurehman chansi
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
xxxxxxxxxx
//abdur rahman kuni dy
public class Main{
public static void main(String[] args){System.out.println("hi there");}
}
xxxxxxxxxx
class basic{
public static void main(String [] args){
System.out.println(" Hello New York!!")// This prints out the sentence "Hello New York!!"
}
}
xxxxxxxxxx
// Java program to find the sum of two numbers
public class SumOfTwoNumbers {
public static void main(String[] args) {
int firstNumber = 5;
int secondNumber = 10;
int sum = firstNumber + secondNumber;
System.out.println("Sum: " + sum);
}
}
// Java program to check if a number is prime
public class PrimeCheck {
public static boolean isPrime(int number) {
if (number <= 1)
return false;
for (int i = 2; i <= Math.sqrt(number); i++) {
if (number % i == 0)
return false;
}
return true;
}
public static void main(String[] args) {
int number = 17;
if (isPrime(number)) {
System.out.println(number + " is a prime number.");
} else {
System.out.println(number + " is not a prime number.");
}
}
}
// Java program to reverse a string
public class StringReversal {
public static String reverseString(String str) {
StringBuilder reversedStr = new StringBuilder();
for (int i = str.length() - 1; i >= 0; i--) {
reversedStr.append(str.charAt(i));
}
return reversedStr.toString();
}
public static void main(String[] args) {
String input = "Hello, World!";
String reversed = reverseString(input);
System.out.println("Reversed String: " + reversed);
}
}