본문 바로가기
728x90

Java/Java Examples11

[Java Examples] 입력한 Integer에 따라서 정사각형 출력하기 예제코드 입력한 Integer에 따라서 정사각형 출력하기 예제코드 포스트 난이도: HOO_Junior # Example code import java.util.Scanner; /** * This class demonstrates a program that generates a square display of 'X' characters. * The size of the square (length of each side) is determined by user input, * constrained to a positive integer no greater than 15. */ public class SquareDisplay { /** * Main method that runs the program. It asks t.. 2024. 3. 31.
[Java Examples] Rectangle.java를 활용해서 집 크기 구하기 예제코드 및 설명 Rectangle.java를 활용해서 집 크기 구하기 예제코드 및 설명 포스트 난이도: HOO_Junior # Example Code public class Immutable_Rectangle { //Fields of the class rectangle final private double length; final private double width; //Getter methods(Accessor methods) public double getLength() { return length; } public double getWidth() { return width; } public double getArea() { return width * length; } //Constructor public Immu.. 2024. 3. 4.
[Java Examples] Array Lists, 어레이 리스트 예제코드 및 설명 Array Lists, 어레이 리스트 예제코드 및 설명 포스트 난이도: HOO_Junior # Example Code import java.util.ArrayList; public class ArrayList_Practice { public static void main(String[] args) { ArrayList nameList = new ArrayList(); nameList.add("Amy"); nameList.add("Ryan"); nameList.add("Jin"); System.out.println("The array has " + nameList.size() + " names."); for(String s : nameList) System.out.println(s); System.out... 2024. 2. 21.
[Java Examples] 다중 if문을 활용한 Troubleshooting 문제 해결 예제코드 및 설명 다중 if문을 활용한 Troubleshooting 문제 해결 예제코드 및 설명 포스트 난이도: HOO_Junior # Example Code import java.util.Scanner; /** * This class provides a step-by-step troubleshooting guide for fixing Wi-Fi connection issues. */ public class WifiTroubleshooter { // Scanner for user input private static final Scanner scanner = new Scanner(System.in); /** * The main method starts the troubleshooting process. * @param a.. 2024. 2. 14.
[Java Examples] 숫자를 로마 숫자로 바꾸기 예제 코드 및 설명 숫자를 로마 숫자로 바꾸기 예제 코드 및 설명 포스트 난이도: HOO_Junior # Example Code /** * This class converts a user-inputted number into its Roman numeral equivalent. * It prompts the user until a number within the range of 1 to 90 is entered. */ import java.util.Scanner; // Import statement for java.util.Scanner public class RomanNumeralConverter { // Variable to store the user's input private int number; /** * Main.. 2024. 2. 14.
[Java Examples] 자바 어레이를 사용해서 오름차순으로 출력하기 자바 어레이를 사용해서 오름차순으로 출력하기 포스트 난이도: HOO_Junior # Example Code import java.util.Arrays; import java.util.Scanner; /** * This class prompts the user to enter three names and then displays them sorted in ascending order. */ public class NameSorter { /** * The main method that initiates the program. * @param args Not used in this application. */ public static void main(String[] args) { // Create a sca.. 2024. 2. 14.
[Java Examples] Method Overloading in Java Method Overloading in Java 포스트 난이도: HOO_Intern # Example Code public class ExMethodOverloading { // Overloaded method for adding two integers public int add(int num1, int num2) { return num1 + num2; } // Overloaded method for adding three integers public int add(int num1, int num2, int num3) { return num1 + num2 + num3; } // Overloaded method for adding two doubles public double add(double num1,.. 2024. 2. 12.
[Java Examples] 상자 용량, 면적 구하는 예제 및 설명 상자 용량, 면적 구하는 예제 및 설명 포스트 난이도: HOO_Intern # Example Code public class Rectangle { private double length; private double width; // Constructor public Rectangle(double len, double w) { length = len; width = w; } // Setter for length public void setLength(double len) { length = len; } // Setter for width public void setWidth(double w) { width = w; } // Getter for length public double getLength() { .. 2024. 2. 7.
[Java Examples] 상자, 직사각형의 크기를 구하는 예제 및 설명 상자, 직사각형의 크기를 구하는 예제 및 설명 포스트 난이도: HOO_Intern # Example Code //Example1 public class Rectangle { private double length; private double width; public void setLength(double l) { length = l; } public double getLength() { return length; } public void setWidth(double w) { width = w; } public double getWidth() { return width; } public static void main(String[] args) { Rectangle rect = new Rectangle();.. 2024. 2. 5.
[Java Example Codes] Method overloading, 오버로딩 예제코드 package HOOAI; class OverloadTest { void test() { System.out.println("HOOAI"); } void test(int a) { System.out.println("a: " + a); } void test(int a, int b) { System.out.println("a: " + a + " b: " + b); } double test(double a) { System.out.println("double a: " + a); return a+a; } } class Overload { public static void main(String args[]) { OverloadTest ot = new OverloadTest(); double ttr; ot.test.. 2021. 3. 31.
[Java Examples] println으로 출력하기 - #System.out.println() C++의 cout이 있다면 자바에는 sout이 있다. sout이란 System.out.println()의 줄임말로써 실제로 자바 코딩에서 사용된다. 다른 언어에서도 단축키가 있지만 필자가 느끼기에 유독 자바는 줄임말을 통한 단축키를 많이 쓴다. 자바 프로그래밍은 한다면 기본적인 단축키는 알아둬야 당신의 퇴근이 빨라진다. System.out.println()을 매번 작성해서 쓰기 번거로우니, sout + Tab 키를 통해서 System.out.println()를 자동으로 작성해준다. 한마디로 System.out.println()의 단축키라고 생각하면 된다. //HOOAI class Example{ //your program begins with a call to main() public static voi.. 2021. 2. 2.
728x90