public class Main {
public static void main(String[] args) {
double result;
result = Math.pow(2, 5); // 2 ni 5-darajaga ko‘tar degani 2 ni 5 martta ko'paytiradi degani
result = Math.abs(-5); // Manfiy sonni musbat qilib beradi -5 -> 5
result = Math.sqrt(9); // Kvadrat ildizini top 9 ning ildizi -> 3
result = Math.round(3.14); // oddiy yaxlitlash 3.14 -> 4 ni butun qilib qaytaradi
result = Math.ceil(3.14); // yuqoriga yaxlitlaydi 3.14 -> 4
result = Math.floor(3.99); // pastga yaxlitlaydi 3.99 -> 3
result = Math.max(10, 20); // Ikkita sondan kattasini oladi
result = Math.min(10, 20); // Ikkita sondan kichkinasini oladi
System.out.println(result);
}
}import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// HYPOTENUSE c = Math.sqrt(a + b);
Scanner scanner = new Scanner(System.in);
double a;
double b;
double c;
System.out.print("Enter the length of side A: ");
a = scanner.nextDouble();
System.out.print("Enter the length of side B: ");
b = scanner.nextDouble();
c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
System.out.println("The hypotenuse (side c) is: " + c + " cm" );
scanner.close();
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double radius;
double circumference;
double area;
double volume;
System.out.print("Enter the radius: ");
radius = scanner.nextDouble();
circumference = 2 * Math.PI * radius;
area = Math.pow(radius, 2);
volume = (4.0 / 3.0) * Math.PI * Math.pow(radius, 3);
System.out.printf("The circumference is: %.1fcm\n", circumference);
System.out.printf("The area is: %.1fcm²\n", area);
System.out.printf("The volume is: %.1fcm³\n", volume);
scanner.close();
}
}
public class Main {
public static void main(String[] args) {
// printf() = is a method used to format output
// %[flags][width][precision][specifier-character]
String name = "Spongebob";
char firstLetter = 'S';
int age = 30;
double height = 60.5;
boolean isEmployed = true;
System.out.printf("Hello %s\n", name );
System.out.printf("Your name starts with a %c\n", firstLetter);
System.out.printf("You are %d years old\n", age);
System.out.printf("You are %f inches tall\n", height);
System.out.printf("Emloyed: %b\n", isEmployed);
System.out.printf("%s is %d years old", name, age);
}
}Forwarded from Webstrom_Tech Family🔥
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Compound interest calculator
Scanner scanner = new Scanner(System.in);
double principal;
double rate;
int timesCompounded;
int years;
double amount;
System.out.print("Enter the principal amount: ");
principal = scanner.nextDouble();
System.out.print("Enter the interest rate (in %): ");
rate = scanner.nextDouble() / 100;
System.out.print("Enter the # of times compounded per years: ");
timesCompounded = scanner.nextInt();
System.out.print("Enter the # of years: ");
years = scanner.nextInt();
amount = principal * Math.pow(1 + rate / timesCompounded, timesCompounded * years);
System.out.printf("The amount after %d years is $%.2f", years, amount);
scanner.close();
}
}
public class Main {
public static void main(String[] args) {
String name = "Password";
// int length = name.length();
// char letter = name.charAt(0);
// int index = name.indexOf(" ");
// int lastIndex = name.lastIndexOf("o");
// name = name.toUpperCase();
// name = name.toUpperCase();
// name = name.trim();
// name = name.replace("o", "a");
// if(name.isEmpty()) {
// System.out.println("Your name is Empty");
// }else {
//
// System.out.println(" Hello" + name);
// }
// if(name.contains(" ")) {
//
// System.out.println("Your name contains a space");
// }else {
// System.out.println("Your name doesn't contain any spaces");
// }
if (name.equalsIgnoreCase("password")) {
System.out.println("Your name can't be password");
}else {
System.out.println("Hello " + name);
}
}
}public class Main {
public static void main(String[] args) {
String txt = "Hello World";
System.out.println(txt.toUpperCase()); // HELLO WORLD
System.out.println(txt.toLowerCase()); // hello world
System.out.println(txt.length()); // 11
String text = "Please locate where locate occurs";
System.out.println(text.indexOf("locate")); // 7
String sample = "Hello";
System.out.println(sample.charAt(0)); // H
System.out.println(sample.charAt(4)); // o
String a = "Hello";
String b = "Hello";
System.out.println(a.equals(b)); // true
System.out.println(a.equalsIgnoreCase(b)); // true
String lyrc = " Hello World ";
System.out.println(lyrc.trim());
String txt1 = "Java is hard";
System.out.println(txt1.replace("hard", "easy"));
String txt2 = "backendDeveloper";
System.out.println(txt2.startsWith("back")); // true
System.out.println(txt2.endsWith("per")); // true
String txt3 = "";
System.out.println(txt3.isEmpty()); // true
String txt4 = "Microservice";
System.out.println(txt4.substring(0, 6)); // Micros
}
}import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// .substring() = A mehtod used to extract a portion of a string
// string.substring(start, end)
// .Substring() - method olib tashlaydi (0, 6) nishonovafotima24@gmail.com -> nishon
Scanner scanner = new Scanner(System.in);
String email;
String username;
String domain;
System.out.println("Enter your email: ");
email = scanner.nextLine();
if (email.contains("@")) {
username = email.substring(0, email.indexOf("@"));
domain = email.substring(email.indexOf("@") + 1);
System.out.println(username);
System.out.println(domain);
}else {
System.out.println("Emails must contains @");
}
scanner.close();
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// WEIGHT CONVERSION PROGRAM
Scanner scanner = new Scanner(System.in);
double weight ;
double newWeight;
int choice;
System.out.println("Weight Conversion Program");
System.out.println("1: Convert lbs to kgs");
System.out.println("2: Convert kgs to lbs");
System.out.print("Choose an option: ");
choice = scanner.nextInt();
if (choice == 1){
System.out.print("Enter the wight in lbs: ");
weight = scanner.nextDouble();
newWeight = weight * 0.453592;
System.out.printf("The new weight in kgs is: %.2f", newWeight);
}
else if (choice == 2){
System.out.print("Enter the wight in kgs: ");
weight = scanner.nextDouble();
newWeight = weight * 2.20462;
System.out.printf("The new weight in lbs is: %.2f", newWeight);
}else {
System.out.println("That was in lbs a valid choice");
}
scanner.close();
}
}
public class Main {
public static void main(String[] args) {
// ternary operator ? = Return 1 of 2 values if a condition is true
// variables = (condition) ? ifTrue : ifFalse
int income = 30000;
double textRate = (income >= 40000) ? 0.25 : 0.15;
System.out.println(textRate);
}
}import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double temp;
double newTemp;
String unit;
System.out.print("Enter the temprature: ");
temp = scanner.nextDouble();
System.out.print("Convert to Celsius to Fahrenheit? (C or F): ");
unit = scanner.next().toUpperCase();
// (condition) ? true : false
newTemp = (unit.equals("C")) ? (temp - 32) * 5 / 9 : (temp * 5 / 9) + 25;
System.out.printf("%.1f°%s", newTemp, unit);
scanner.close();
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your age: ");
int age = scanner.nextInt();
System.out.print("Do you have VIP pass? (true/false): ");
boolean hasVIPPass = scanner.nextBoolean();
System.out.print("Do you want 3D? (true/false): ");
boolean wants3D = scanner.nextBoolean();
System.out.println("\n--- Result ---");
if (age >= 18) {
if (hasVIPPass) {
if (wants3D) {
System.out.println("You can watch VIP 3D movie!");
} else {
System.out.println("You can watch VIP Standard movie!");
}
} else {
System.out.println("You can watch Standard movie only.");
}
} else {
System.out.println("No movie for you!");
}
scanner.close();
}
}