인사말
안녕하세요. 이 글을 읽고 계신다면 정보처리기사 또는 정보처리산업기사 수험생이실 것 같습니다.
여러 좋은 서적에서 이론을 잘 설명하고 있지만, 코딩 문제의 경우 같은 문제를 여러 번 풀다 보면 답이 머리에 기억되어 새로운 문제가 필요하게 되는 순간이 옵니다.
그럴 때 더 많은 문제를 풀어보고 도움이 되게 하고자 여러 C언어, JAVA, Python 문제를 변형 시키고 직접 컴파일하여 답을 확인하면서 문제를 만들었습니다.
정보처리 실기를 공부하시는 모든 수험생 여러분, 목표하는 모든 것이 이루어지는 그날까지 응원하겠습니다. 화이팅!
목표를 향해 열심히 노력하시고, 좋은 결과 있기를 기원합니다!
정보처리기사 실기 언어 코딩 기출변형 문제
1. 출력 값을 작성하시오.
public class ConfusingExample {
public static void main(String[] args) {
String x = "" + 5 + 7;
String y = 5 + 7 + "";
String z = "5" + (7 + 9);
String w = (5 + 7) + "9";
System.out.println("x: " + x);
System.out.println("y: " + y);
System.out.println("z: " + z);
System.out.println("w: " + w);
}
}
정답
x: 57
y: 12
z: 516
w: 129
2. 출력 값을 작성하시오.
class Base {
public Base() {
System.out.print("X");
}
public void action() {
System.out.print("Y");
}
public void actionA() {
System.out.print("Z");
}
}
class Derived extends Base {
public Derived() {
System.out.print("W");
}
public void action() {
System.out.print("V");
}
public void actionB() {
System.out.print("U");
}
}
public class ConfusingExample {
public static void main(String[] args) {
Derived d = new Derived();
d.action();
d.actionA();
Base b = new Derived();
b.action();
b.actionA();
}
}
정답
XWVZXWVZ
3. 출력 값을 작성하시오.
class Counter {
public int instanceCount = 0;
static int totalCount = 0;
public Counter() {
instanceCount++;
totalCount++;
}
public void showCounts() {
System.out.println("Instance Count: " + instanceCount);
System.out.println("Total Count: " + totalCount);
}
}
public class CounterTest {
public static void main(String[] args) {
Counter counter1 = new Counter();
counter1.showCounts();
Counter counter2 = new Counter();
counter2.showCounts();
Counter counter3 = new Counter();
counter3.showCounts();
System.out.println("Final Total Count: " + Counter.totalCount);
}
}
정답
Instance Count: 1
Total Count: 1
Instance Count: 1
Total Count: 2
Instance Count: 1
Total Count: 3
Final Total Count: 3
4. 출력 값을 작성하시오.
abstract class Gadget {
String model;
abstract public String getModel(String val);
public String getModel() {
return "Gadget model: " + model;
}
}
class Smartphone extends Gadget {
public Smartphone(String val) {
model = super.model = val;
}
public String getModel(String val) {
return "Smartphone model: " + val;
}
public String getModel(int val) {
return "Smartphone version: " + val;
}
}
public class GadgetTest {
public static void main(String[] args) {
Gadget device = new Smartphone("Galaxy S21");
System.out.println(device.getModel());
Smartphone phone = new Smartphone("iPhone 13");
System.out.println(phone.getModel("iPhone 13 Pro"));
System.out.println(phone.getModel(2021));
}
}
정답
Gadget model: Galaxy S21
Smartphone model: iPhone 13 Pro
Smartphone version: 2021
5. 출력 값을 작성하시오.
interface Shape {
double getArea();
double getPerimeter();
}
class Rectangle implements Shape {
private double width;
private double height;
Rectangle(double width, double height) {
this.width = width;
this.height = height;
}
public double getArea() {
return width * height;
}
public double getPerimeter() {
return 2 * (width + height);
}
}
class Triangle implements Shape {
private double side1;
private double side2;
private double side3;
Triangle(double side1, double side2, double side3) {
this.side1 = side1;
this.side2 = side2;
this.side3 = side3;
}
public double getArea() {
double s = (side1 + side2 + side3) / 2;
return Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));
}
public double getPerimeter() {
return side1 + side2 + side3;
}
}
public class ShapeTest {
public static void main(String[] args) {
Rectangle rectangle = new Rectangle(5, 10);
System.out.println("Rectangle Area: " + rectangle.getArea());
System.out.println("Rectangle Perimeter: " + rectangle.getPerimeter());
Triangle triangle = new Triangle(3, 4, 5);
System.out.println("Triangle Area: " + triangle.getArea());
System.out.println("Triangle Perimeter: " + triangle.getPerimeter());
}
}
정답
Rectangle Area: 50.0
Rectangle Perimeter: 30.0
Triangle Area: 6.0
Triangle Perimeter: 12.0
6. 출력 값을 작성하시오.
public class OverloadingExample {
public int sum(int a, int b) {
return a + b;
}
public double sum(double a, double b) {
return a + b;
}
public String sum(String a, String b) {
return a + b;
}
public static void main(String[] args) {
OverloadingExample example = new OverloadingExample();
int result1 = example.sum(3, 5);
System.out.println(result1);
double result2 = example.sum(3.5, 2.5);
System.out.println(result2);
String result3 = example.sum("Hello, ", "World!");
System.out.println(result3);
}
}
정답
8
6.0
Hello, World!
7. 출력 값을 작성하시오.
class Parent {
void display() {
System.out.println("Parent's display method");
}
}
class Child extends Parent {
void display() {
System.out.println("Child's display method");
}
}
public class OverridingExample {
public static void main(String[] args) {
Parent obj1 = new Parent();
Parent obj2 = new Child();
obj1.display();
obj2.display();
}
}
정답
Parent’s display method
Child’s display method
8. 출력 값을 작성하시오.
class Animal {
void eat() {
System.out.println("Animal is eating");
}
void sleep() {
System.out.println("Animal is sleeping");
}
}
class Dog extends Animal {
void bark() {
System.out.println("Dog is barking");
}
}
class Puppy extends Dog {
void play() {
System.out.println("Puppy is playing");
}
}
public class InheritanceExample {
public static void main(String[] args) {
Animal animal = new Animal();
Dog dog = new Dog();
Puppy puppy = new Puppy();
animal.eat();
animal.sleep();
dog.eat();
dog.sleep();
dog.bark();
puppy.eat();
puppy.sleep();
puppy.bark();
puppy.play();
}
}
정답
Animal is eating
Animal is sleeping
Animal is eating
Animal is sleeping
Dog is barking
Animal is eating
Animal is sleeping
Dog is barking
Puppy is playing
9. 출력 값을 작성하시오.
class Vehicle {
protected String brand;
public Vehicle(String brand) {
this.brand = brand;
}
public void displayInfo() {
System.out.println("This is a vehicle of brand: " + brand);
}
}
class Car extends Vehicle {
private int doors;
public Car(String brand, int doors) {
super(brand);
this.doors = doors;
}
public void displayInfo() {
System.out.println("This car is a " + brand + " with " + doors + " doors");
}
public void start() {
System.out.println("Car started");
}
}
public class VehicleTest {
public static void main(String[] args) {
Vehicle vehicle1 = new Vehicle("Generic Vehicle");
vehicle1.displayInfo();
Car car1 = new Car("Toyota", 4);
car1.displayInfo();
car1.start();
Vehicle car2 = new Car("BMW", 2);
car2.displayInfo();
}
}
정답
This is a vehicle of brand: Generic Vehicle
This car is a Toyota with 4 doors
Car started
This car is a BMW with 2 doors
10. 출력 값을 작성하시오.
public class ConfusingCalculation {
public static int calculateA() {
return 10;
}
public static int calculateB() {
return (50 + calculateA());
}
public static int calculateC() {
return (300 + calculateB());
}
public static void main(String[] args) {
int result = 0;
result += calculateC();
System.out.println(result);
}
}
정답
360