coding with ☕️
2 subscribers
262 photos
14 videos
11 files
165 links
Anwendungsentwicklung
Download Telegram
import java.util.Scanner;

public class Main {
public static void main(String[] args) {

// LOGICAL OPERATORS

Scanner scanner = new Scanner(System.in);

// username must be between 4=12 characters
// username must be not contain space or underscores

String username;
System.out.print("Enter your new username: ");
username = scanner.nextLine();

if (username.length() < 4 || username.length() > 12) {

System.out.println("Username must be between 4-12 characters!");
} else if (username.contains(" ") || username.contains("_")) {
System.out.println("Username must not contain Spaces or Underscores!");
} else {
System.out.println("Welcome! " + username);
}

scanner.close();
}
}
import java.util.Locale;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {

// WHILE LOOP = repeat some code forever
// while some condition remains true


Scanner scanner = new Scanner(System.in);
int age = 0;

do {
System.out.println("Your age can't be negative");
System.out.print("Enter your age: ");
age = scanner.nextInt();
}while (age < 0);

System.out.println("Your age " + age + " years old");



scanner.close();
}
}
🔖 Kodni formatlash

🔗 VS Code: Shift + Alt + F

📌 IntelliJ IDEA: Ctrl + Alt + L
import java.util.Random;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {

Random random = new Random();
Scanner scanner = new Scanner(System.in);

int guess;
int attempts = 0;
int min = 1;
int max = 100;
int randomNumber = random.nextInt(min, max + 1);

System.out.println("Number Guessing Game");
System.out.printf("Guess a number between %d-%d\n", min, max);

do {
System.out.print("Enter a Guess: ");
guess = scanner.nextInt();
attempts++;

if (guess < randomNumber) {
System.out.println("TOO LOW! TRY again");

} else if (guess > randomNumber) {
System.out.println("TOO HIGH! TRY again");
} else {
System.out.println("CORRECT! The number was " + randomNumber);
System.out.println("# of attempts: " + attempts);
}

} while (guess != randomNumber);


scanner.close();
}
}
import java.util.Scanner;
public class First {
public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter number of students: ");
int studentCount = scanner.nextInt();


String[] names = new String[studentCount];
int[] grades = new int[studentCount];


for (int i = 0; i < studentCount; i++) {
System.out.println("\nStudent " + (i + 1));

System.out.print("Name: ");
names[i] = scanner.next();

System.out.print("Grade (0-100): ");
grades[i] = scanner.nextInt();
}

int sum = 0;
int max = grades[0];
int min = grades[0];

for (int i = 0; i < studentCount; i++) {
sum += grades[i];

if (grades[i] > max) {
max = grades[i];
}

if (grades[i] < min) {
min = grades[i];
}
}

double average = (double) sum / studentCount;


System.out.println("\n===== STUDENT RESULTS =====");

for (int i = 0; i < studentCount; i++) {
System.out.println(names[i] + " → " + grades[i]);
}

System.out.println("\nAverage grade: " + average);
System.out.println("Highest grade: " + max);
System.out.println("Lowest grade: " + min);
scanner.close();

}
}
import java.util.Scanner;

public class First {
public static void main(String[] args) throws InterruptedException {


Scanner scanner = new Scanner(System.in);

System.out.print("How many seconds to countdown from?: ");
int start = scanner.nextInt();


for (int i = start; i > 0; i--) {
System.out.println(i);
Thread.sleep(1000);
}

System.out.println("HAPPY NEW YEAR!");

scanner.close();
}
}
public class First {
public static void main(String[] args) {

// break = break out of a loop (STOP)
// continue = skip current iteration of a loop (SKIP)

for (int i = 0; i < 10; i++) {
if (i == 5){
continue;
}
System.out.print(i + " ");
}


}
}
import java.util.Scanner;

public class First {
public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int rows;
int columns;
char symbol;

System.out.print("Enter the # of rows: ");
rows = scanner.nextInt();

System.out.print("Enter the # of columns: ");
columns = scanner.nextInt();

System.out.print("Enter the symbol to use: ");
symbol = scanner.next().charAt(0);


for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
System.out.print(symbol);
}
System.out.println();
}

scanner.close();
}
}
public class First {
public static void main(String[] args) {

// A method = is a block of code which only runs when it is called.

// You can pass data, known as (parameters), into a method.

// Methods = are used to perform certain actions, and they are also known as (functions).

String name = "Bro";
int age = 25;

happyBirthday(name, age);

}

static void happyBirthday(String name, int age) {
System.out.println("Happy birthday to you!");
System.out.printf("Happy birthday dear %s!\n", name);
System.out.printf("You are %d years old!\n", age);
System.out.println("Happy birthday to you!\n");
}
}
public class First {
public static void main(String[] args) {

int age = 12;
if (ageCheck((age))) {
System.out.println("You may sign up!");
} else {
System.out.println("You must be 18+ to sign up!");
}
}

static void happyBirthday(String name, int age) {
System.out.println("Happy birthday to you!");
System.out.printf("Happy birthday dear %s!\n", name);
System.out.printf("You are %d years old!\n", age);
System.out.println("Happy birthday to you!\n");
}

static double square(double number) {
return number * number;
}

static double cube(double number) {
return number * number * number;
}

static String getFullName(String first, String last) {
return first + " " + last;

}

static boolean ageCheck(int age) {
if (age >= 18) {
return true;
} else {
return false;
}
}

}