본문으로 건너뛰기
cccskills
무료GitHub에 공개

pseudocode-to-java-code

Converts pseudocode descriptions and algorithm specifications into complete, executable Java code. Use this skill when you need to implement algorithms from pseudocode, translate algorithm descriptions to Java, generate Java code from specifications, convert textbook algorithms to working code, or create executable implementations from high-level descriptions. Preserves logic and control flow while handling Java idioms, data structures, and includes test cases for verification.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(3)

  • SKILL.md7.4 KB
  • assets/java_template.java361 B
  • references/mapping_patterns.md5.8 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Pseudocode to Java Code

Overview

This skill converts pseudocode descriptions and algorithm specifications into complete, executable Java programs. It preserves the original logic and control flow, applies appropriate Java idioms and data structures, and generates test cases to verify correctness.

Workflow

1. Provide Pseudocode Input

Give the pseudocode or algorithm specification. Formats accepted:

  • Structured pseudocode with keywords (IF, FOR, WHILE, etc.)
  • Algorithm descriptions in plain text
  • Textbook-style algorithm specifications
  • Flowchart-like descriptions

Example:

FUNCTION findMax(array)
    max ← array[0]
    FOR i FROM 1 TO LENGTH(array) - 1 DO
        IF array[i] > max THEN
            max ← array[i]
        END IF
    END FOR
    RETURN max
END FUNCTION

2. Specify Requirements (Optional)

Provide additional context:

  • Expected input/output types
  • Performance requirements
  • Specific Java version or features to use
  • Edge cases to handle
  • Naming preferences

3. Generate Java Code

The skill will produce:

  • Complete Java class with proper structure
  • Converted algorithm as Java method(s)
  • Appropriate data structures and types
  • Necessary imports
  • Main method with test cases

Output Example:

import java.util.*;

public class ArrayMaxFinder {

    public static void main(String[] args) {
        ArrayMaxFinder solution = new ArrayMaxFinder();

        // Test case 1: Normal array
        int[] arr1 = {3, 7, 2, 9, 1};
        System.out.println("Max: " + solution.findMax(arr1)); // Expected: 9

        // Test case 2: Single element
        int[] arr2 = {5};
        System.out.println("Max: " + solution.findMax(arr2)); // Expected: 5
    }

    /**
     * Finds the maximum value in an array
     * @param array the input array
     * @return the maximum value
     */
    public int findMax(int[] array) {
        int max = array[0];
        for (int i = 1; i < array.length; i++) {
            if (array[i] > max) {
                max = array[i];
            }
        }
        return max;
    }
}

4. Review Mapping Summary

The skill provides a summary explaining:

  • How pseudocode constructs map to Java
  • Data structure choices
  • Type decisions
  • Any assumptions made

Example Summary:

Mapping Summary:
- FUNCTION → public method
- array parameter → int[] array
- LENGTH(array) → array.length
- FOR loop → standard Java for loop
- IF condition → if statement
- RETURN → return statement
- Added null/empty array handling
- Included test cases for verification

5. Test and Verify

Run the generated code:

javac ArrayMaxFinder.java
java ArrayMaxFinder

Verify output matches expected results.

Common Conversions

Control Structures

IF-ELSE:

Pseudocode: IF condition THEN ... ELSE ... END IF
Java: if (condition) { ... } else { ... }

FOR Loop:

Pseudocode: FOR i FROM 1 TO n DO ... END FOR
Java: for (int i = 1; i <= n; i++) { ... }

WHILE Loop:

Pseudocode: WHILE condition DO ... END WHILE
Java: while (condition) { ... }

Data Structures

Array:

Pseudocode: DECLARE array[n] OF INTEGER
Java: int[] array = new int[n];

List:

Pseudocode: DECLARE list AS LIST OF INTEGER
Java: List<Integer> list = new ArrayList<>();

Map:

Pseudocode: DECLARE map AS MAP FROM STRING TO INTEGER
Java: Map<String, Integer> map = new HashMap<>();

Set:

Pseudocode: DECLARE set AS SET OF INTEGER
Java: Set<Integer> set = new HashSet<>();

Operations

String Operations:

  • LENGTH(string) → string.length()
  • SUBSTRING(string, start, end) → string.substring(start, end)
  • CONCATENATE(str1, str2) → str1 + str2

Math Operations:

  • POWER(base, exp) → Math.pow(base, exp)
  • SQRT(value) → Math.sqrt(value)
  • MAX(a, b) → Math.max(a, b)

Use Cases

Use Case 1: Implement Textbook Algorithm

User: "Convert this binary search pseudocode to Java"
→ Provide pseudocode
→ Generate complete Java implementation
→ Include test cases with sorted arrays
→ Verify correctness

Use Case 2: Algorithm Assignment

User: "I have this sorting algorithm in pseudocode, need Java code"
→ Analyze pseudocode structure
→ Generate Java with proper array handling
→ Add test cases with various inputs
→ Provide complexity analysis

Use Case 3: Interview Preparation

User: "Convert this graph traversal algorithm to Java"
→ Map pseudocode to Java collections
→ Use appropriate data structures (Queue, Set)
→ Generate clean, interview-ready code
→ Include edge case handling

Use Case 4: Learning Java

User: "I understand the algorithm in pseudocode, how does it look in Java?"
→ Generate side-by-side comparison
→ Explain Java-specific idioms
→ Show best practices
→ Provide runnable examples

Best Practices

  1. Type Safety: Choose appropriate Java types based on pseudocode context

  2. Null Handling: Add null checks for reference types

  3. Edge Cases: Include handling for empty inputs, boundary conditions

  4. Naming Conventions: Use camelCase for variables, PascalCase for classes

  5. Comments: Preserve pseudocode as comments for clarity

  6. Test Coverage: Generate tests for normal cases, edge cases, and error conditions

  7. Imports: Include all necessary import statements

  8. Documentation: Add Javadoc comments for public methods

Advanced Features

Generic Types

When pseudocode uses generic collections:

Pseudocode: DECLARE list AS LIST OF TYPE
Java: List<T> list = new ArrayList<>();

Exception Handling

Add appropriate exception handling:

try {
    // algorithm implementation
} catch (ArrayIndexOutOfBoundsException e) {
    // handle error
}

Optimization

Apply Java-specific optimizations:

  • Use StringBuilder for string concatenation
  • Use enhanced for loops where appropriate
  • Apply stream operations for functional style

Limitations

  1. Ambiguous Types: May need clarification for ambiguous pseudocode types

  2. Complex Data Structures: Custom data structures may need additional specification

  3. Concurrency: Pseudocode doesn't usually specify thread safety

  4. I/O Operations: File/network operations need additional context

  5. Language Features: Some pseudocode constructs may not have direct Java equivalents

Resources

references/mapping_patterns.md

Comprehensive guide to pseudocode-to-Java mappings:

  • Control structure conversions
  • Data structure mappings
  • Common operations
  • Algorithm patterns
  • Type conversions
  • Best practices

Read this reference when you need detailed mapping rules, want to understand conversion patterns, or need examples of specific constructs.

assets/java_template.java

Basic Java class template:

  • Standard class structure
  • Main method with test cases
  • Placeholder for methods
  • Proper formatting

Use this template as a starting point for generated code.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Applies abstract interpretation using different abstract domains (intervals, octagons, polyhedra, sign, congruence) to statically analyze program variables and infer invariants, value ranges, and relationships. Use when analyzing program properties, inferring loop invariants, detecting potential errors, or understanding variable relationships through static analysis.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2552026년 8월 21일 업데이트

Uses abstract interpretation to automatically infer loop invariants, function preconditions, and postconditions for formal verification. Generates invariants that capture program behavior and support correctness proofs in Dafny, Isabelle, Coq, and other verification systems. Use when adding formal specifications to code, generating verification conditions, inferring contracts for functions, or discovering loop invariants for proofs.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2552026년 8월 21일 업데이트

Performs abstract interpretation over source code to infer possible program states, variable ranges, and data properties without executing the program. Reports potential runtime errors including out-of-bounds accesses, null dereferences, type inconsistencies, division by zero, and integer overflows. Use when analyzing code for potential runtime errors, performing static analysis, checking safety properties, or verifying program behavior without execution.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2552026년 8월 21일 업데이트

Performs abstract interpretation to produce summarized execution traces and high-level program behavior representations. Highlights key control flow paths, variable relationships, loop invariants, function summaries, and potential runtime states using abstract domains (intervals, signs, nullness, etc.). Use when analyzing program behavior, understanding execution paths, computing loop invariants, tracking variable ranges, detecting potential runtime errors, or generating program summaries without concrete execution.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2552026년 8월 21일 업데이트

Create ACSL (ANSI/ISO C Specification Language) formal annotations for C/C++ programs. Use this skill when working with formal verification, adding function contracts (requires/ensures), loop invariants, assertions, memory safety annotations, or any ACSL specifications. Supports Frama-C verification and generates comprehensive formal specifications for C/C++ code.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2552026년 8월 21일 업데이트

CLI-based browser automation with persistent page state using ref-based element interaction. Use when users ask to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

ArabelaTso/Skills-4-SE2552026년 8월 21일 업데이트

ArabelaTso의 스킬 모두 보기

이 스킬의 문제 신고