Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

feat(dspy): added beginner example for multi-input-output

williambrachcfbd1a16f9f2
diff --git a/examples/multi-input-output/beginner-multi-input-output.ipynb b/examples/multi-input-output/beginner-multi-input-output.ipynb
new file mode 100644
index 000000000..3a40eb810
--- /dev/null
+++ b/examples/multi-input-output/beginner-multi-input-output.ipynb
@@ -0,0 +1,829 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<img src=\"../../docs/images/DSPy8.png\" alt=\"DSPy7 Image\" height=\"150\"/>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# DSPy Tutorial: Building a Code Plagiarism Detector\n",
+ "\n",
+ "If you've ever felt intimidated by DSPy, don't worry—it might look complex at first glance, but it's actually quite approachable. This tutorial will walk you through the process of building a project, providing a clear, step-by-step approach to understanding and implementing DSPy concepts.\n",
+ "\n",
+ "## TLDR 🚀\n",
+ "\n",
+ "We're going to build a system for code plagiarism detection. Our goal is to compare two input code files, determine if plagiarism has occurred, and provide an explanation for the result. \n",
+ "\n",
+ "This project will showcase:\n",
+ "\n",
+ "- Multiple inputs and outputs\n",
+ "- Double validation techniques\n",
+ "\n",
+ "I strongly recommend to read the [DSPy Cheatsheet](https://dspy-docs.vercel.app/docs/cheatsheet) it will help you with quick start.\n",
+ "\n",
+ "## How to Start?\n",
+ "\n",
+ "A highly effective practice I've found to be game-changing when starting any DSPy project is to answer [these 8 key questions](https://dspy-docs.vercel.app/docs/building-blocks/solving_your_task). This exercise helps you develop a clear vision for your project before diving into the code.\n",
+ "\n",
+ "Here's an example of how your answers might look:\n",
+ "1. **Define your task**\n",
+ " - Expected input: Two input code files (strings containing plain code) to be compared.\n",
+ " - Expected output:\n",
+ " - Plagiarism detection result (Yes/No)\n",
+ " - Explanation/justification of the result\n",
+ " - Quality and Cost Specifications: Cost is not a concern; quality is the main priority. We want to try different models.\n",
+ "\n",
+ "2. **Define your pipeline**\n",
+ " - We don't need any external tools or document retrieval. It will be a simple chain-of-thought step, as we want to evaluate LLM capabilities for plagiarism detection.\n",
+ "\n",
+ "3. **Explore a few examples**\n",
+ " - We explored LLM capabilities for plagiarism detection using a few examples with ChatGPT and Claude, yielding promising results.\n",
+ "\n",
+ "4. **Define your data**\n",
+ " - We are working with a dataset from the publication: [Source Code Plagiarism Detection in Academia with Information Retrieval: Dataset and the Observation](https://github.com/oscarkarnalim/sourcecodeplagiarismdataset/blob/master/IR-Plag-Dataset.zip)\n",
+ " - We selected a subset and manually labeled the dataset with our output labels. This dataset should be used for training and testing, while the rest of the original dataset should be used for evaluation.\n",
+ " - Dataset: [train.csv](/data/train.tsv) (65 samples)\n",
+ " - When you don't hae labeled dataset, it is good idea to try hand-labeling a few examples to get a sense of the task. It will help you to understand the task better and also increse the quality of program.\n",
+ "\n",
+ "5. **Define your metric**\n",
+ " - We are dealing with a **classification problem**, so we will use accuracy as our main metric. \n",
+ " - Our metric will be simple: if pred_label == true_label then 1 else 0.\n",
+ " - As second evaluation we will be evaluating the quality of the explanation via secondary LLM.\n",
+ "\n",
+ "6. **Collect preliminary \"zero-shot\" evaluations**\n",
+ " - Done in code.\n",
+ "\n",
+ "7. **Compile with a DSPy optimizer**\n",
+ " - We don't want to update weights of the LLM, so we are looking at optimizers such as:\n",
+ " - BootstrapFewShot\n",
+ " - BootstrapFewShotWithRandomSearch\n",
+ " - MIPRO\n",
+ " - ...\n",
+ "\n",
+ "8. **Iterate**\n",
+ " - Regroup and attack again!\n",
+ "\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import os\n",
+ "import re\n",
+ "\n",
+ "import dspy\n",
+ "import pandas as pd\n",
+ "from dotenv import load_dotenv\n",
+ "from dspy.evaluate import Evaluate\n",
+ "from dspy.teleprompt import (\n",
+ " BootstrapFewShot,\n",
+ " BootstrapFewShotWithRandomSearch,\n",
+ " KNNFewShot,\n",
+ " MIPROv2,\n",
+ ")\n",
+ "\n",
+ "# load your environment variables from .env file\n",
+ "load_dotenv()\n",
+ "\n",
+ "# azure-openai model deployment\n",
+ "AZURE_OPENAI_KEY = os.getenv(\"AZURE_OPENAI_KEY\")\n",
+ "AZURE_OPENAI_ENDPOINT = os.getenv(\"AZURE_OPENAI_ENDPOINT\")\n",
+ "AZURE_OPENAI_DEPLOYMENT = os.getenv(\"AZURE_OPENAI_DEPLOYMENT\")\n",
+ "AZURE_OPENAI_VERSION = os.getenv(\"AZURE_OPENAI_VERSION\")\n",
+ "\n",
+ "# openai model deployment\n",
+ "\n",
+ "OPENAI_MODEL = os.getenv(\"OPENAI_MODEL\")\n",
+ "OPENAI_API_KEY = os.getenv(\"OPENAI_API_KEY\")\n",
+ "\n",
+ "# ollama deployment\n",
+ "OLLAMA_URL = os.getenv(\"OLLAMA_URL\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# 0. Load dataset\n",
+ "\n",
+ "Our first task is to load our dataset. Each entry in our dataset will consist of the following components:\n",
+ "\n",
+ "* `sample_1`: The first code sample to be analyzed\n",
+ "* `sample_2`: The second code sample to be compared against the first\n",
+ "* `plagiarized`: A boolean value (True if plagiarism is detected, False otherwise)\n",
+ "* `reason`: A detailed explanation of the plagiarism detection result\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df = pd.read_csv(\"train.csv\", sep=\"\\t\")\n",
+ "df.head()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# 1. Prepare dataset\n",
+ "\n",
+ "DSPy utilizes special objects called [`Example`](https://dspy-docs.vercel.app/docs/deep-dive/data-handling/examples#creating-an-example) to structure and process data. Our next task is to convert our raw dataset into a collection of these `Example` objects.\n",
+ "\n",
+ "## Creating Custom Example Objects\n",
+ "\n",
+ "For our plagiarism detection system, we'll create `Example` objects with the following attributes:\n",
+ "- `code_sample_1`: The first code sample to analyze\n",
+ "- `code_sample_2`: The second code sample to compare\n",
+ "- `plagiarized`: Boolean indicating whether plagiarism was detected\n",
+ "- `explanation`: Detailed reasoning for the plagiarism decision\n",
+ "\n",
+ "## Specifying Inputs\n",
+ "\n",
+ "It's crucial to inform DSPy which attributes serve as inputs for our model. We accomplish this using the `.with_inputs()` method. In our case, we'll specify:\n",
+ "\n",
+ "```python\n",
+ ".with_inputs(\"code_sample_1\", \"code_sample_2\")\n",
+ "```\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def create_example(row: pd.Series) -> dspy.Example:\n",
+ " return dspy.Example(\n",
+ " code_sample_1=row[\"sample_1\"],\n",
+ " code_sample_2=row[\"sample_2\"],\n",
+ " plagiarized=\"Yes\" if row[\"plagiarized\"] else \"No\",\n",
+ " explanation=row[\"reason\"],\n",
+ " ).with_inputs(\"code_sample_1\", \"code_sample_2\")\n",
+ "\n",
+ "\n",
+ "examples = []\n",
+ "for _, row in df.iterrows():\n",
+ " example = create_example(row)\n",
+ " examples.append(example)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# 2. DSPy setup\n",
+ "\n",
+ "DSPy is designed to be compatible with a variety of language models and their respective clients. For this tutorial, we will primarily utilize GPT-4 through the [Azure client](https://github.com/stanfordnlp/dspy/blob/main/dsp/modules/azure_openai.py). However, to demonstrate DSPy's flexibility, we will also provide configuration examples for other popular options:\n",
+ "\n",
+ "1. [OpenAI client](https://dspy-docs.vercel.app/docs/deep-dive/language_model_clients/remote_models/OpenAI)\n",
+ "2. Local models via [Ollama](https://github.com/stanfordnlp/dspy/blob/main/dsp/modules/ollama.py)\n",
+ "\n",
+ "## Custom Client Implementation\n",
+ "\n",
+ "If your preferred language model client is not natively supported by DSPy, you have the option to implement a custom client. For detailed instructions on creating a custom client, please refer to this [comprehensive guide - custom-lm-client](https://dspy-docs.vercel.app/docs/deep-dive/language_model_clients/custom-lm-client).\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# client for AzureOpenAI\n",
+ "lm = dspy.AzureOpenAI(\n",
+ " api_base=AZURE_OPENAI_ENDPOINT,\n",
+ " api_version=AZURE_OPENAI_VERSION,\n",
+ " deployment_id=AZURE_OPENAI_DEPLOYMENT,\n",
+ " api_key=AZURE_OPENAI_KEY,\n",
+ ")\n",
+ "\n",
+ "# client for OpenAI\n",
+ "# lm = dspy.OpenAI(\n",
+ "# api_key=OPENAI_API_KEY,\n",
+ "# model=OPENAI_MODEL,\n",
+ "# )\n",
+ "\n",
+ "# client for Ollama\n",
+ "# model_name = \"llama3.1\"\n",
+ "# lm = dspy.OllamaLocal(base_url=OLLAMA_URL, model=model_name)\n",
+ "\n",
+ "dspy.settings.configure(lm=lm)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# 3. Setting up signature and module\n",
+ "\n",
+ "\n",
+ "## Core DSPy Components\n",
+ "\n",
+ "[dspy.Signature](https://dspy-docs.vercel.app/docs/building-blocks/signatures) and [dspy.Module](https://dspy-docs.vercel.app/docs/building-blocks/modules) are fundamental building blocks for DSPy programs:\n",
+ "\n",
+ "- **Signature**: A declarative specification of the input/output behavior of a DSPy module.\n",
+ "- **Module**: A building block for programs that leverage Language Models (LMs).\n",
+ "\n",
+ "## Types of DSPy Modules\n",
+ "\n",
+ "DSPy offers various module types, each serving different purposes:\n",
+ "\n",
+ "1. [dspy.Predict](https://dspy-docs.vercel.app/api/modules/Predict)\n",
+ " - Basic predictor\n",
+ " - Maintains the original signature\n",
+ " - Handles key forms of learning (storing instructions, demonstrations, and LM updates)\n",
+ " - Most similar to direct LM usage\n",
+ "\n",
+ "2. [dspy.ChainOfThought](https://dspy-docs.vercel.app/api/modules/ChainOfThought)\n",
+ " - Enhances the LM to think step-by-step before producing the final response\n",
+ " - Modifies the signature to incorporate intermediate reasoning steps\n",
+ "\n",
+ "3. [Additional Advanced Modules](https://dspy-docs.vercel.app/api/category/modules)\n",
+ " - DSPy library offers a range of more specialized modules for complex tasks\n",
+ "\n",
+ "### Recommendation for starting\n",
+ "\n",
+ "For those new to DSPy, it's advisable to start with `dspy.Predict`. Its simplicity makes it ideal for understanding the basics of DSPy operation. Once you've successfully implemented your program using `dspy.Predict`, you can explore more advanced modules like `dspy.ChainOfThought` to potentially enhance your model's performance.\n",
+ "\n",
+ "For an overview of other prompting techniques beyond zero-shot learning, refer to the [Prompting Guide](https://www.promptingguide.ai/techniques). This resource covers various methods that can enhance your DSPy applications as you progress."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "class PlagiarismSignature(dspy.Signature):\n",
+ " # Clarify something about the nature of the task (expressed below as a docstring)! \n",
+ " \"\"\"Detect if two code samples are plagiarized. In plagiarized field answer only : Yes if the code samples are plagiarized, No otherwise. In explenation field add the reason why the code samples are/ are not plagiarized.\"\"\"\n",
+ "\n",
+ " # Supply hints on the nature of an input field, expressed as a desc keyword argument for dspy.InputField.\n",
+ " code_sample_1 = dspy.InputField(desc=\"The first code sample to compare\")\n",
+ " code_sample_2 = dspy.InputField(desc=\"The second code sample to compare\")\n",
+ "\n",
+ " # Supply constraints on an output field, expressed as a desc keyword argument for dspy.OutputField.\n",
+ " explanation = dspy.OutputField(\n",
+ " desc=\"Explanation or reason why the code samples are/ are not plagiarized\"\n",
+ " )\n",
+ " plagiarized = dspy.OutputField(\n",
+ " desc=\"Yes/No indicating if code samples are plagiarized\"\n",
+ " )\n",
+ "\n",
+ "\n",
+ "class PlagiarismCoT(dspy.Module):\n",
+ " def __init__(self) -> None:\n",
+ " super().__init__()\n",
+ " # Define the program as a ChainOfThought object\n",
+ " # self.prog = dspy.PredictiveText(PlagiarismSignature)\n",
+ " self.prog = dspy.ChainOfThought(PlagiarismSignature)\n",
+ "\n",
+ " def forward(self, code_sample_1: str, code_sample_2: str) -> PlagiarismSignature:\n",
+ "\n",
+ " # here you can do any processing you want, calling your function, etc.\n",
+ " # modifying your code, inputs etc.\n",
+ " # similar to pytorch forward function\n",
+ "\n",
+ " # returned signature object \n",
+ " prediction = self.prog(code_sample_1=code_sample_1, code_sample_2=code_sample_2)\n",
+ " return prediction"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## 3.1 Test your module with zero-shot program"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "output = PlagiarismCoT()(examples[0].code_sample_1, examples[0].code_sample_1)\n",
+ "print(f\"plagiarized : {output.plagiarized}\")\n",
+ "print(f\"explanation : {output.explanation}\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# 4. Create metric for your programs\n",
+ "\n",
+ "Creating evaluation metric is a crucial component of the DSPy pipeline. This step is often the most complex function in your DSPy application.\n",
+ "\n",
+ "### Metric Structure\n",
+ "\n",
+ "In DSPy, metrics (or evaluation functions) must adhere to the following structure:\n",
+ "\n",
+ "1. **Arguments**: \n",
+ " - Two required arguments, both of type `dspy.Example`:\n",
+ " - The ground truth example from the dataset\n",
+ " - The predicted example from the model\n",
+ " - An optional third argument called `trace`\n",
+ "\n",
+ "2. **Return Value**: \n",
+ " - A numerical score (float, int, or bool)\n",
+ " - For binary metrics, return `True` for correct predictions and `False` for incorrect ones\n",
+ "\n",
+ "For more detailed information on creating metrics in DSPy, refer to the [official documentation on metrics](https://dspy-docs.vercel.app/docs/building-blocks/metrics)."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def validate_answer(\n",
+ " example: dspy.Example, pred: PlagiarismSignature, trace: object = None\n",
+ ") -> bool:\n",
+ " \"\"\"\n",
+ " Validate the predicted plagiarism answer against the example answer.\n",
+ "\n",
+ " This function compares the predicted plagiarism answer with the example answer,\n",
+ " focusing on a simple \"yes\" or \"no\" response. It extracts the core answer from\n",
+ " the prediction, handling potential variations in formatting and capitalization.\n",
+ "\n",
+ " Parameters:\n",
+ " - example (dspy.Example): The example object containing the correct answer.\n",
+ " - pred (PlagiarismSignature): The prediction object containing the model's answer.\n",
+ " - trace (object, optional): Unused parameter, kept for compatibility.\n",
+ "\n",
+ " Returns:\n",
+ " - bool: True if the predicted answer matches the example answer, False otherwise.\n",
+ "\n",
+ " The function returns False if either the predicted or example answer is None,\n",
+ " or if any exception occurs during the validation process.\n",
+ " \"\"\"\n",
+ " try:\n",
+ " if pred.plagiarized is None:\n",
+ " return False\n",
+ "\n",
+ " # Extract the first line of the predicted answer, convert to lowercase\n",
+ " pred_plag = pred.plagiarized.strip().lower().split(\"\\n\")[0]\n",
+ "\n",
+ " # Define a regex pattern to match \"yes\" or \"no\"\n",
+ " yes_no_pattern = r\"\\b(yes|no)\\b\"\n",
+ "\n",
+ " # Search for the pattern in the predicted answer\n",
+ " match = re.search(yes_no_pattern, pred_plag)\n",
+ "\n",
+ " # If a match is found, use it; otherwise, use the entire predicted answer\n",
+ " extracted_answer = match.group(1) if match else pred.plagiarized.strip().lower()\n",
+ "\n",
+ " if example.plagiarized is None:\n",
+ " return False\n",
+ "\n",
+ " score = (\n",
+ " True if extracted_answer == example.plagiarized.strip().lower() else False\n",
+ " )\n",
+ " except Exception:\n",
+ " score = False\n",
+ " return score"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## 4.1 Test your metric with evaluate\n",
+ "\n",
+ "Now we can evaluate zero-shot program with our `validate_answer` function. This will be bottom baseline for our program."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "evaluate = Evaluate(\n",
+ " devset=examples,\n",
+ " metric=validate_answer,\n",
+ " num_threads=4,\n",
+ " display_progress=True,\n",
+ " display_table=0,\n",
+ ")\n",
+ "\n",
+ "# zero-shot evaluation on examples\n",
+ "score = evaluate(PlagiarismCoT())"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## 4.2 When you can't use simple programmatic metrics and you need more brain power\n",
+ "\n",
+ "In our metric, we are only evaluating the `plagiarized` field. We are not evaluating the `explanation` field. If we wanted to evaluate the `explanation`, which is a string (reasoning), we could use a text similarity metric (cosine similarity, for example) or another LLM to evaluate it.\n",
+ "\n",
+ "The advantage of using another LLM is that we can evaluate the explanation in a more human-like way, but be careful with this approach. It could be very expensive and add more time to your program's runtime.\n",
+ "\n",
+ "More examples of implementing this type of metric can be found in the [tweets example](https://github.com/stanfordnlp/dspy/blob/main/examples/tweets/tweet_metric.py)."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Define the signature for automatic assessments.\n",
+ "class Assess(dspy.Signature):\n",
+ " \"\"\"Assess the similarity of a of inputs. Answer only Yes if inputs are similar or No if not.\"\"\"\n",
+ "\n",
+ " original_explanation = dspy.InputField()\n",
+ " predicted_reasoning = dspy.InputField()\n",
+ " similar = dspy.OutputField(desc=\"Yes if inputs are similar or No if not\")\n",
+ "\n",
+ "\n",
+ "gpt_judge = dspy.AzureOpenAI(\n",
+ " api_base=AZURE_OPENAI_ENDPOINT,\n",
+ " api_version=AZURE_OPENAI_VERSION,\n",
+ " deployment_id=AZURE_OPENAI_DEPLOYMENT,\n",
+ " api_key=AZURE_OPENAI_KEY,\n",
+ ")\n",
+ "\n",
+ "\n",
+ "def validate_answer_with_explanation(\n",
+ " example: dspy.Example, pred: PlagiarismSignature, trace: object = None\n",
+ ") -> bool:\n",
+ "\n",
+ " # Extract the true explanation from the example\n",
+ " true_explanation = example.explanation\n",
+ "\n",
+ " # Extract the predicted explanation from the prediction\n",
+ " pred_explanation = pred.explanation\n",
+ "\n",
+ " # Use a language model (gpt_judge) to assess the similarity of explanations\n",
+ " with dspy.context(lm=gpt_judge):\n",
+ " # Create an Assess object to compare the explanations\n",
+ " similar = dspy.Predict(Assess)(\n",
+ " original_explanation=true_explanation, predicted_reasoning=pred_explanation\n",
+ " )\n",
+ "\n",
+ " # Check if the explanations are deemed similar (converting to lowercase for case-insensitive comparison)\n",
+ " similar_score = similar.similar.lower() == \"yes\"\n",
+ "\n",
+ " # Validate the plagiarism answer using the existing validate_answer function\n",
+ " plagiarized_score = validate_answer(example, pred, trace)\n",
+ "\n",
+ " # Return True only if both the explanation is similar and the plagiarism answer is correct\n",
+ " return similar_score and plagiarized_score"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "evaluate_with_explanation = Evaluate(\n",
+ " devset=examples,\n",
+ " metric=validate_answer_with_explanation,\n",
+ " num_threads=4,\n",
+ " display_progress=True,\n",
+ " display_table=0,\n",
+ ")\n",
+ "\n",
+ "# zero-shot evaluation on examples\n",
+ "score = evaluate_with_explanation(PlagiarismCoT())"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# 5. DSPy Magic - Optimizers\n",
+ "\n",
+ "## TLDR on Optimizers\n",
+ "\n",
+ "Optimizers in DSPy are powerful tools that handle prompt engineering for you. Think of them as \"functions\" that automate and improve the process of crafting effective prompts. There are several types of optimizers available in DSPy, but in this tutorial, we'll focus on the first two:\n",
+ "\n",
+ "1. **Automatic Few-Shot Learning**: \n",
+ " - Adds examples to your prompts.\n",
+ " - Key optimizers to explore: `BootstrapFewShot` and `BootstrapFewShotWithRandomSearch`\n",
+ "\n",
+ "2. **Automatic Instruction Optimization**: \n",
+ " - Produces optimal instructions for the prompt.\n",
+ " - In the case of MIPRO, also optimizes the set of few-shot examples.\n",
+ " - Key optimizer to explore: [`MIPROv2`](https://github.com/stanfordnlp/dspy/blob/main/dspy/teleprompt/mipro_optimizer_v2.py)\n",
+ "\n",
+ "3. Automatic Finetuning:\n",
+ " - Used to fine-tune the underlying Language Model(s).\n",
+ "\n",
+ "4. Program Transformations:\n",
+ " - Ensembles a set of DSPy programs and either uses the full set or randomly samples a subset into a single program.\n",
+ "\n",
+ "If you're new to optimizers and unsure where to start, `BootstrapFewShotWithRandomSearch` is a safe and effective choice for beginners.\n",
+ "\n",
+ "## Read the Documentation!\n",
+ "\n",
+ "For more detailed information about optimizers, please refer to the [official DSPy documentation on optimizers](https://dspy-docs.vercel.app/docs/building-blocks/optimizers)."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## 5.1 Example of BootstrapFewShot\n",
+ "\n",
+ "[BooststrapFewShot docs](https://dspy-docs.vercel.app/docs/deep-dive/teleprompter/bootstrap-fewshot), [BootstrapFewShot class](https://github.com/stanfordnlp/dspy/blob/main/dspy/teleprompt/bootstrap.py) "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "config = {\"max_bootstrapped_demos\": 8, \"max_labeled_demos\": 8}\n",
+ "\n",
+ "optimizer = BootstrapFewShot(metric=validate_answer, **config)\n",
+ "optimized_program = optimizer.compile(PlagiarismCoT(), trainset=examples)\n",
+ "score = evaluate(optimized_program)\n",
+ "optimized_program.save(\"BootstrapFewShot_program\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## 5.2 Example of BootstrapFewShotWithRandomSearch\n",
+ "\n",
+ "[BootstrapFewShotWithRandomSearch class](https://github.com/stanfordnlp/dspy/blob/main/dspy/teleprompt/random_search.py) "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "config = {\n",
+ " \"max_bootstrapped_demos\": 8,\n",
+ " \"max_labeled_demos\": 8,\n",
+ " \"num_candidate_programs\": 5,\n",
+ " \"num_threads\": 4,\n",
+ "}\n",
+ "\n",
+ "optimizer = BootstrapFewShotWithRandomSearch(metric=validate_answer, **config)\n",
+ "optimized_program = optimizer.compile(PlagiarismCoT(), trainset=examples)\n",
+ "score = evaluate(optimized_program)\n",
+ "optimized_program.save(\"BootstrapFewShotWithRandomSearch_program\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## 5.3 Example of KNNFewShot\n",
+ "\n",
+ "[KNNFewShot class](https://github.com/stanfordnlp/dspy/blob/main/dspy/teleprompt/knn_fewshot.py) "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "k = 3\n",
+ "optimizer = KNNFewShot(k, examples)\n",
+ "optimized_program = optimizer.compile(PlagiarismCoT(), trainset=examples)\n",
+ "score = evaluate(optimized_program)\n",
+ "optimized_program.save(\"KNNFewShot_program\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## 5.4 Example of MIPROv2\n",
+ "\n",
+ "[MIPROv2 paper](https://arxiv.org/abs/2406.11695), [MIPROv2 class](https://github.com/stanfordnlp/dspy/blob/main/dspy/teleprompt/mipro_optimizer_v2.py) "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "n = 20 # The number of instructions and fewshot examples that we will generate and optimize over\n",
+ "batches = 20 # The number of optimization trials to be run (we will test out a new combination of instructions and fewshot examples in each trial)\n",
+ "temperature = 1 # The temperature configured for generating new instructions\n",
+ "eval_kwargs = {\"num_threads\": 4, \"display_progress\": False, \"display_table\": 0}\n",
+ "optimizer = MIPROv2(\n",
+ " prompt_model=lm,\n",
+ " task_model=lm,\n",
+ " metric=validate_answer,\n",
+ " num_candidates=n,\n",
+ " init_temperature=temperature,\n",
+ " verbose=True,\n",
+ ")\n",
+ "optimized_program = optimizer.compile(\n",
+ " PlagiarismCoT(),\n",
+ " trainset=examples,\n",
+ " num_batches=batches,\n",
+ " max_bootstrapped_demos=16,\n",
+ " max_labeled_demos=16,\n",
+ " requires_permission_to_run=False,\n",
+ " eval_kwargs=eval_kwargs,\n",
+ ")\n",
+ "score = evaluate(optimized_program)\n",
+ "optimized_program.save(\"MIPROv2_program\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# 6. Loading a Saved Program\n",
+ "\n",
+ "Loading a program from a saved file is a straightforward process in DSPy. Here's how you can do it:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "loaded_program = PlagiarismCoT()\n",
+ "loaded_program.load(path=\"BootstrapFewShotWithRandomSearch_program\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## 6.1 Deploying a DSPy Program\n",
+ "\n",
+ "Deploying a DSPy program in a production environment can be challenging, as DSPy is primarily designed for research and experimentation at the moment. However, there are two effective methods to successfully deploy a DSPy program in production:\n",
+ "\n",
+ "### 6.1.1 Using DSPy as a Library\n",
+ "\n",
+ "This method involves saving, loading, and using your DSPy program directly:\n",
+ "\n",
+ "1. Save your DSPy program to a file using the `.save()` method.\n",
+ "2. Load your DSPy program from the file using the `.load()` method.\n",
+ "3. Use the loaded program to make predictions in your production environment.\n",
+ "\n",
+ "### 6.1.2 Extracting Prompts and Calling Your LLM Directly\n",
+ "\n",
+ "This approach involves:\n",
+ "\n",
+ "1. Extracting the optimized prompts from your DSPy program.\n",
+ "2. Implementing these prompts in your production code.\n",
+ "3. Calling your Language Model (LLM) directly with the extracted prompts.\n",
+ "\n",
+ "Each method has its advantages and may be more suitable depending on your specific use case and production environment constraints."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# dummy call of your program\n",
+ "res = loaded_program(examples[0].code_sample_1, examples[0].code_sample_2)\n",
+ "\n",
+ "# find last call in your llm\n",
+ "last_prompt = lm.inspect_history(n=1)\n",
+ "with open(\"inspect_history.txt\", \"w\") as f:\n",
+ " f.write(str(last_prompt))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Refining Your Prompt\n",
+ "\n",
+ "You can now streamline your prompt by removing unnecessary parameters and utilizing Python's string formatting to incorporate your inputs. Here's an enhanced version of the prompt:\n",
+ "\n",
+ "```python\n",
+ "prompt = f\"\"\"\n",
+ "Detect if two code samples are plagiarized. Answer only 'Yes' in the plagiarized field if the code samples are plagiarized, 'No' otherwise. Provide the reasoning in the explanation field.\n",
+ "\n",
+ "Format:\n",
+ "Code Sample 1: [First code sample to compare]\n",
+ "Code Sample 2: [Second code sample to compare]\n",
+ "\n",
+ "Reasoning: Let's analyze step by step to determine if the code samples are plagiarized...\n",
+ "\n",
+ "Explanation: [Detailed explanation of why the code samples are or are not plagiarized]\n",
+ "\n",
+ "Plagiarized: [Yes/No]\n",
+ "\n",
+ "Example:\n",
+ "Code Sample 1: \n",
+ "import java.util.Scanner;\n",
+ "public class T3 {{\n",
+ " public static void main(String[] args) {{\n",
+ " Scanner input = new Scanner(System.in);\n",
+ " System.out.print(\"Enter weight in pounds: \");\n",
+ " double weight = input.nextDouble();\n",
+ " System.out.print(\"Enter feet: \");\n",
+ " double feet = input.nextDouble();\n",
+ " System.out.print(\"Enter inches: \");\n",
+ " double inches = input.nextDouble();\n",
+ " double height = feet * 12 + inches;\n",
+ " double bmi = weight * 0.45359237 / ((height * 0.0254) * (height * 0.0254));\n",
+ " System.out.println(\"BMI is \" + bmi);\n",
+ " if (bmi < 18.5) System.out.println(\"Underweight\");\n",
+ " else if (bmi < 25) System.out.println(\"Normal\");\n",
+ " else if (bmi < 30) System.out.println(\"Overweight\");\n",
+ " else System.out.println(\"Obese\");\n",
+ " }}\n",
+ "}}\n",
+ "\n",
+ "Code Sample 2:\n",
+ "import java.util.*;\n",
+ "public class L2 {{\n",
+ " public static void main(String[] args) {{\n",
+ " Scanner sc = new Scanner(System.in);\n",
+ " System.out.print(\"Enter weight in pounds: \");\n",
+ " double berat = sc.nextDouble();\n",
+ " System.out.print(\"Enter feet: \");\n",
+ " double feet = sc.nextDouble();\n",
+ " System.out.print(\"Enter inches: \");\n",
+ " double inci = sc.nextDouble();\n",
+ " double tinggi = feet * 12 + inci;\n",
+ " double bmi = berat * 0.45359237 / ((tinggi * 0.0254) * (tinggi * 0.0254));\n",
+ " System.out.println(\"BMI is \" + bmi);\n",
+ " if (bmi < 18.5) {{ System.out.println(\"Underweight\"); }}\n",
+ " else if (bmi < 25) {{ System.out.println(\"Normal\"); }}\n",
+ " else if (bmi < 30) {{ System.out.println(\"Overweight\"); }}\n",
+ " else {{ System.out.println(\"Obese\"); }}\n",
+ " }}\n",
+ "}}\n",
+ "\n",
+ "Reasoning: Let's analyze the code samples step by step to determine if they are plagiarized...\n",
+ "\n",
+ "Explanation: The two code samples are nearly identical in structure, logic, and even specific constants used, with only minor differences in variable names and formatting. This level of similarity is extremely unlikely to occur independently and strongly indicates that one sample was copied from the other or both were derived from a common source.\n",
+ "\n",
+ "Plagiarized: Yes\n",
+ "\n",
+ "Now, analyze the following code samples:\n",
+ "\n",
+ "Code Sample 1: {code_sample_1}\n",
+ "\n",
+ "Code Sample 2: {code_sample_2}\n",
+ "\n",
+ "Reasoning: Let's analyze step by step to determine if the code samples are plagiarized...\n",
+ "\"\"\"\n",
+ "```\n",
+ "**Just be aware that you need to do your own parsing of the output of the LLM.**"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Thanks! 🙌\n",
+ "\n",
+ "In case of any questions, feel free to reach out to me: \n",
+ "William Brach - [@williambrach](https://x.com/williambrach) - [email protected]"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "dspy",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.12.3"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/examples/multi-input-output/train.csv b/examples/multi-input-output/train.csv
new file mode 100644
index 000000000..dc293ea15
--- /dev/null
+++ b/examples/multi-input-output/train.csv
@@ -0,0 +1,64 @@
+sample_1 sample_2 plagiarized reason
+"public class T1 { public static void main(String[] args) { System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); } }" "/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author CB6AB3315634A1E4D11B091BA48B60BA 7E51EEA5FA101ED4DADE9AD3A7A072BB 2F809B10D1ABEDBF2EC288F851B3EBBB */ public class T01 { public static void main(String[] args){ for(int i = 0; i < 5; i++){ System.out.println(""Welcome To Java""); } } }" False The two code samples, while producing similar output, employ distinctly different programming approaches - one using repetitive print statements and the other utilizing a more efficient for loop. This fundamental difference in implementation, along with variations in code structure and comments, suggests that these are independently written solutions to a common beginner programming task rather than instances of plagiarism.
+"public class T1 { public static void main(String[] args) { System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); } }" "/** * * @author 65FBEF05E01FAC390CB3FA073FB3E8CF (452BF208BF901322968557227B8F6EFE010) */ public class T01 { public static void main(String[] args) { for (int i = 0; i < 5; i++) { System.out.println(""Welcome To Java""); } } }" False The code samples demonstrate different approaches to achieving the same simple task, with one using repetitive print statements and the other employing a more efficient loop structure. While the core functionality is identical, the implementation differences and the presence of unique elements like the author comment in the second sample suggest these are likely independent solutions to a common beginner programming exercise rather than a case of direct plagiarism.
+"public class T1 { public static void main(String[] args) { System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); } }" "/** * * @author CB6AB3315634A1E4D11B091BA48B60BA */ public class Nomor1_2451041557A22145B3701B0184109CAB013 { /** * @param args the command line arguments */ public static void main(String[] args) { for(int i=0;i<5;i++) { System .out.println(""Welcome To Java""); } } }" False The two code samples produce the same output but utilize different programming approaches, with Sample 1 using repetitive print statements and Sample 2 employing a more efficient loop structure. While the core idea is similar, the implementation details, coding style, and level of programming sophistication differ significantly between the two samples, suggesting independent development rather than plagiarism.
+"public class T1 { public static void main(String[] args) { System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); } }" "* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author 19984DCAEA13176BBB694F62BA6B5B35 */ public class L1 { public static void main(String[] args) { System.out.println(""""Welcome to Java""""); System.out.println(""""Welcome to Java""""); System.out.println(""""Welcome to Java""""); System.out.println(""""Welcome to Java""""); System.out.println(""""Welcome to Java""""); } }" True "The two code samples are nearly identical in their core functionality, with both containing the exact same main method that prints ""Welcome to Java"" five times using identical System.out.println statements. The only significant differences are the class names and the presence of auto-generated comments in the second sample, which are superficial changes that do not alter the underlying logic or purpose of the code, strongly indicating that one sample was copied from the other with minimal alterations. "
+"public class T1 { public static void main(String[] args) { System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); } }" "/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author 19984DCAEA13176BBB694F62BA6B5B35 */ public class L2 { public static void main(String[] args) { System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); } }" True The two code samples contain identical main methods with the exact same five print statements, which is highly unlikely to occur by chance. The only differences are superficial (class names, comments, and formatting), while the core functionality remains identical, strongly indicating that one code sample was copied from the other or both were copied from a common source.
+"public class T1 { public static void main(String[] args) { System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); } }" "public class L3 { public static void main(String[] args) { System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); } }" True The code samples are identical except for the class names, exhibiting the same structure, content, and even the unusual repetition of print statements. Such a high degree of similarity, especially in a simple program that could be written in many different ways, is extremely unlikely to occur by chance and strongly indicates that one sample was copied from the other with only minimal alteration.
+"public class T1 { public static void main(String[] args) { System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); } }" "public class L4 { public static void print() { System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); } public static void main(String[] args) { print(); } }" True The code samples show significant similarities in their output and inefficient approach of repeating the same print statement five times without using a loop, which raises suspicion of potential plagiarism. However, the differences in class structure and method implementation suggest that if copying occurred, it wasn't a direct copy-paste, and more context would be needed to conclusively determine plagiarism.
+"public class T1 { public static void main(String[] args) { System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); } }" "public class L5 { public static void print() { for (int i = 0; i < 5; i++) { System.out.print(""Welcome to Java\n""); } } public static void main(String[] args) { print(); } }" True "The code samples exhibit plagiarism due to their identical output and core functionality, despite differences in implementation. The verbatim use of the specific phrase ""Welcome to Java"" in both samples, combined with the same overall goal and language, strongly suggests that one solution was derived from the other, even if attempts were made to disguise this through minor structural changes."
+"public class T1 { public static void main(String[] args) { System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); System.out.println(""Welcome to Java""); } }" "public class L6 { public static void print() { for (int i = 5; i > 0; i--) { System.out.print(""""Welcome to Java\n""""); } } public static void main(String[] args) { print(); } }" True These code samples can be considered plagiarism because they produce identical, specific output and solve the same unusual task, with the second sample appearing to be an attempt to disguise copied code through minimal modifications. Despite superficial differences in implementation (using a loop and separate method in Sample 2), the core functionality and purpose remain the same, indicating a lack of originality that would likely be considered plagiarism in academic or professional contexts.
+"import java.util.Scanner; public class T2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Enter radius of the cylinder System.out.print(""Enter the radius and length of a cylinder: ""); double radius = input.nextDouble(); double length = input.nextDouble(); double area = radius * radius * 3.14159; double volume = area * length; System.out.println(""The area is "" + area); System.out.println(""The volume of the cylinder is "" + volume); } }" "import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author CB6AB3315634A1E4D11B091BA48B60BA 7E51EEA5FA101ED4DADE9AD3A7A072BB 2F809B10D1ABEDBF2EC288F851B3EBBB */ public class T02 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); System.out.print(""Enter the radius and length of a cylinder: ""); double radius = sc.nextDouble(); double length = sc.nextDouble(); double area = radius * radius * 3.14159; double volume = area * length; System.out.println(""The area is "" + (float)area); System.out.printf(""The volume is %.1f"", volume); System.out.println(); } }" False While the two programs are very similar in structure and functionality, they appear to be standard solutions to a common programming exercise for calculating cylinder measurements, which explains their resemblance without necessarily indicating plagiarism. Small differences in implementation details, variable naming, and output formatting suggest these could be independent solutions to the same problem rather than direct copies.
+"import java.util.Scanner; public class T2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Enter radius of the cylinder System.out.print(""Enter the radius and length of a cylinder: ""); double radius = input.nextDouble(); double length = input.nextDouble(); double area = radius * radius * 3.14159; double volume = area * length; System.out.println(""The area is "" + area); System.out.println(""The volume of the cylinder is "" + volume); } }" "import java.util.Scanner; /** * * @author 65FBEF05E01FAC390CB3FA073FB3E8CF (452BF208BF901322968557227B8F6EFE010) */ public class T02 { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.print(""Enter the radius and length of a cylinder: ""); float r = s.nextFloat(); float l = s.nextFloat(); System.out.println(""The area is "" + r * r * 3.14159); System.out.println(""The volume is "" + (r * r * 3.14159) * l); } }" False The code samples show significant structural and conceptual similarities, including identical problem-solving approaches and nearly verbatim output statements, which suggest a common source or assignment. However, the differences in variable naming, data types, calculation methods, and overall code style indicate that these are likely independent implementations of the same problem rather than direct copying, making it difficult to definitively classify this as plagiarism without more context.
+"import java.util.Scanner; public class T2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Enter radius of the cylinder System.out.print(""Enter the radius and length of a cylinder: ""); double radius = input.nextDouble(); double length = input.nextDouble(); double area = radius * radius * 3.14159; double volume = area * length; System.out.println(""The area is "" + area); System.out.println(""The volume of the cylinder is "" + volume); } }" "import java.util.Scanner; /** * * @author CB6AB3315634A1E4D11B091BA48B60BA */ public class Nomor2_2451041557A22145B3701B0184109CAB013 { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print(""Enter the radius and length of a cylinder : ""); double radius = sc.nextDouble(); double length = sc.nextDouble(); double area = (radius * radius) * 3.14159; double volume = area * length; System.out.println(""The area is : "" + area); System.out.println(""The volume is : "" + volume); } }" False These code samples do not demonstrate plagiarism because they are solving a common, simple programming problem that naturally leads to similar implementations. While they share basic structure and formulas, there are distinct differences in naming, formatting, and specific implementation details that indicate independent work.
+"import java.util.Scanner; public class T2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Enter radius of the cylinder System.out.print(""Enter the radius and length of a cylinder: ""); double radius = input.nextDouble(); double length = input.nextDouble(); double area = radius * radius * 3.14159; double volume = area * length; System.out.println(""The area is "" + area); System.out.println(""The volume of the cylinder is "" + volume); } }" "import java.util.Scanner; public class L1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(""""Enter the radius and length of a cylinder: """"); double radius = input.nextDouble(); double length = input.nextDouble(); double area = radius * radius * 3.14159; double volume = area * length; System.out.println(""""The area is """" + area + """", """"); System.out.print(""""The volume of the cylinder is """" + volume); } }" True The two code samples are nearly identical in structure, logic, and even comments, with only minor differences in class names and output formatting. This level of similarity, including matching variable names and the specific order of operations, strongly indicates that one sample was copied from the other or both were derived from a common source, rather than being independently developed solutions to the same problem.
+"import java.util.Scanner; public class T2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Enter radius of the cylinder System.out.print(""Enter the radius and length of a cylinder: ""); double radius = input.nextDouble(); double length = input.nextDouble(); double area = radius * radius * 3.14159; double volume = area * length; System.out.println(""The area is "" + area); System.out.println(""The volume of the cylinder is "" + volume); } }" "import java.util.*; public class L2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(""Enter the radius and length of a cylinder: ""); double jari2 = input.nextDouble(); double panjang = input.nextDouble(); double luas = jari2 * jari2 * 3.14159; double total = luas * panjang; System.out.println(""The area is "" + luas); System.out.println(""The volume of the cylinder is "" + total); } }" True The two code samples have identical overall structure, logic, calculations, and output strings, which is too similar to be coincidental. While there are superficial differences like some variable names and comments, the core implementation is essentially the same, strongly suggesting that one was copied from the other with only minor modifications.
+"import java.util.Scanner; public class T2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Enter radius of the cylinder System.out.print(""Enter the radius and length of a cylinder: ""); double radius = input.nextDouble(); double length = input.nextDouble(); double area = radius * radius * 3.14159; double volume = area * length; System.out.println(""The area is "" + area); System.out.println(""The volume of the cylinder is "" + volume); } }" "import java.util.*; public class L3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); double jari2 = 0; double panjang = 0; System.out.print(""Enter the radius and length of a cylinder: ""); jari2 = input.nextDouble(); panjang = input.nextDouble(); double luas = jari2 * jari2 * 3.14159; double total = luas * panjang; System.out.print(""The area is "" + luas + "" , ""); System.out.println(""The volume of the cylinder is "" + total); } }" True The code samples exhibit nearly identical structure, logic, and even specific wording in key areas such as user prompts and output statements, which is unlikely to occur independently. Despite minor differences in variable names and formatting, the overall similarity in implementation, including the use of the same mathematical constant (3.14159) and calculation methods, strongly suggests that one code sample was derived from the other or both were derived from a common source.
+"import java.util.Scanner; public class T2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Enter radius of the cylinder System.out.print(""Enter the radius and length of a cylinder: ""); double radius = input.nextDouble(); double length = input.nextDouble(); double area = radius * radius * 3.14159; double volume = area * length; System.out.println(""The area is "" + area); System.out.println(""The volume of the cylinder is "" + volume); } }" "import java.util.*; public class L4 { public static double hitLuas(double jari2) { return jari2 * jari2 * 3.14159; } public static double total(double luas, double panjang) { return luas * panjang; } public static void main(String[] args) { Scanner input = new Scanner(System.in); double jari2 = 0; double panjang = 0; System.out.print(""Enter the radius and length of a cylinder: ""); jari2 = input.nextDouble(); panjang = input.nextDouble(); double luas = hitLuas(jari2); double total = total(luas,panjang); System.out.print(""The area is "" + luas + "" , ""); System.out.println(""The volume of the cylinder is "" + total); } }" True The code samples show significant similarities in their overall structure, purpose, and specific details like the input prompt and pi value, strongly suggesting they are not independently created. However, there are also notable differences in implementation, such as the use of methods in the second sample, which indicates some level of individual work or modification rather than direct copying.
+"import java.util.Scanner; public class T2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Enter radius of the cylinder System.out.print(""Enter the radius and length of a cylinder: ""); double radius = input.nextDouble(); double length = input.nextDouble(); double area = radius * radius * 3.14159; double volume = area * length; System.out.println(""The area is "" + area); System.out.println(""The volume of the cylinder is "" + volume); } }" "import java.util.*; public class L5 { public static double hitLuas(double jari2) { return jari2 * jari2 * 3.14159; } public static double total(double luas, double panjang) { return luas * panjang; } public static void main(String[] args) { Scanner input = new Scanner(System.in); double jari2, panjang; double luas, total; System.out.print(""Enter the radius and length of a cylinder: ""); jari2 = input.nextDouble(); panjang = input.nextDouble(); luas = hitLuas(jari2); total = total(luas, panjang); System.out.print(""The area is "" + luas + "" , ""); System.out.println(""The volume of the cylinder is "" + total); } }" True The two code samples share identical core logic, user prompts, and a specific pi approximation, which is highly unlikely to occur independently. While the second sample attempts to disguise potential copying through restructuring and variable renaming, these superficial changes do not mask the underlying similarities that strongly suggest derivation from the first code sample.
+"import java.util.Scanner; public class T2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Enter radius of the cylinder System.out.print(""Enter the radius and length of a cylinder: ""); double radius = input.nextDouble(); double length = input.nextDouble(); double area = radius * radius * 3.14159; double volume = area * length; System.out.println(""The area is "" + area); System.out.println(""The volume of the cylinder is "" + volume); } }" "import java.util.*; public class L6 { public static double hitLuas(double jari2) { return jari2 * jari2 * 3.14159; } public static double total(double luas, double panjang) { return luas * panjang; } public static void main(String[] args) { Scanner input = new Scanner(System.in); double jari2, panjang; double luas, total; jari2 = 0; panjang = 0; System.out.print(""Enter the radius and length of a cylinder: ""); for (int i = 0; i < 1; i++) { jari2 = input.nextDouble(); panjang = input.nextDouble(); } luas = hitLuas(jari2); total = total(luas, panjang); System.out.print(""The area is "" + luas + "" , ""); System.out.println(""The volume of the cylinder is "" + total); } }" True The two code samples share significant similarities in structure, core logic, and specific elements like the input prompt and pi value, which are unlikely to occur by chance in independently developed programs. While there are some differences in implementation details, these appear to be superficial changes that don't fundamentally alter the underlying approach, suggesting that one code sample may have been derived from the other with attempts to disguise the similarity.
+"import java.util.Scanner; public class T3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Prompt the user to enter weight in pounds System.out.print(""Enter weight in pounds: ""); double weight = input.nextDouble(); // Prompt the user to enter height System.out.print(""Enter feet: ""); double feet = input.nextDouble(); System.out.print(""Enter inches: ""); double inches = input.nextDouble(); double height = feet * 12 + inches; // Compute BMI double bmi = weight * 0.45359237 / ((height * 0.0254) * (height * 0.0254)); // Display result System.out.println(""BMI is "" + bmi); if (bmi < 18.5) System.out.println(""Underweight""); else if (bmi < 25) System.out.println(""Normal""); else if (bmi < 30) System.out.println(""Overweight""); else System.out.println(""Obese""); } }" "import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author CB6AB3315634A1E4D11B091BA48B60BA 7E51EEA5FA101ED4DADE9AD3A7A072BB 2F809B10D1ABEDBF2EC288F851B3EBBB */ public class T03 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); System.out.print(""Enter weight in pounds: ""); int weight = sc.nextInt(); System.out.print(""Enter feet: ""); int feet = sc.nextInt(); System.out.print(""Enter inches: ""); int inches = sc.nextInt(); int height = feet * 12 + inches; double bmi = weight * 0.45359237 / ((height * 0.0254) * (height * 0.0254)); System.out.println(""BMI is "" + bmi); if(bmi < 18.5){ System.out.println(""Underweight""); }else if(bmi >= 18.5 && bmi < 25){ System.out.println(""Normal""); }else if(bmi >= 35){ System.out.println(""Obese""); } } }" False These code samples are not plagiarized because they represent standard solutions to a common beginner programming exercise (BMI calculator), which naturally leads to similarities in structure, calculations, and variable names. The differences in implementation details, such as variable types, input methods, and BMI classification thresholds, along with unique elements like the encoded header comment in the second sample, indicate these are independently written programs following similar assignment requirements.
+"import java.util.Scanner; public class T3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Prompt the user to enter weight in pounds System.out.print(""Enter weight in pounds: ""); double weight = input.nextDouble(); // Prompt the user to enter height System.out.print(""Enter feet: ""); double feet = input.nextDouble(); System.out.print(""Enter inches: ""); double inches = input.nextDouble(); double height = feet * 12 + inches; // Compute BMI double bmi = weight * 0.45359237 / ((height * 0.0254) * (height * 0.0254)); // Display result System.out.println(""BMI is "" + bmi); if (bmi < 18.5) System.out.println(""Underweight""); else if (bmi < 25) System.out.println(""Normal""); else if (bmi < 30) System.out.println(""Overweight""); else System.out.println(""Obese""); } }" "import java.util.Scanner; /** * * @author 65FBEF05E01FAC390CB3FA073FB3E8CF (452BF208BF901322968557227B8F6EFE010) */ public class T03 { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.print(""Enter weight in pounds: ""); float w=s.nextFloat(); System.out.print(""Enter feet: ""); float f=s.nextFloat(); System.out.print(""Enter inches: ""); float i=s.nextFloat(); float h=f*12+i; float bmi = (float) ((w*0.45359237)/((h*0.0254)*(h*0.0254))); System.out.println(""BMI is ""+bmi); if(bmi<18.5){ System.out.println(""Underweight""); } else if (bmi>=18.5 && bmi<25){ System.out.println(""Normal""); } else if (bmi>=25 && bmi<35){ System.out.println(""Overweight""); } else if (bmi>=35) { System.out.println(""Obese""); } } }" False The two code samples, while solving the same problem and sharing some similarities due to the nature of the task, have enough distinct differences in implementation details, variable naming, and coding style to be considered separate, original works rather than instances of plagiarism.
+"import java.util.Scanner; public class T3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Prompt the user to enter weight in pounds System.out.print(""Enter weight in pounds: ""); double weight = input.nextDouble(); // Prompt the user to enter height System.out.print(""Enter feet: ""); double feet = input.nextDouble(); System.out.print(""Enter inches: ""); double inches = input.nextDouble(); double height = feet * 12 + inches; // Compute BMI double bmi = weight * 0.45359237 / ((height * 0.0254) * (height * 0.0254)); // Display result System.out.println(""BMI is "" + bmi); if (bmi < 18.5) System.out.println(""Underweight""); else if (bmi < 25) System.out.println(""Normal""); else if (bmi < 30) System.out.println(""Overweight""); else System.out.println(""Obese""); } }" "import java.util.Scanner; /** * * @author CB6AB3315634A1E4D11B091BA48B60BA */ public class Nomor3_2451041557A22145B3701B0184109CAB013 { /** * @param args the command line arguments / public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print(""Enter weight in pounds: ""); int weight = sc.nextInt(); System.out.print(""Enter feet: ""); int feet = sc.nextInt(); System.out.print(""Enter inch: ""); int inches = sc.nextInt(); int height = feet12 + inches; double bmi = weight0.45359237/((height0.0254)(height0.0254)); System.out.println(""BMI is "" + bmi); if(bmi<18.5){ System.out.println(""underweight""); } else if(bmi>=18.5 && bmi<25){ System.out.println(""Normal""); } else if(bmi>=25 && bmi<35){ System.out.println(""overweight""); } else if(bmi >35){ System.out.println(""obese""); } } }" False The two code samples, while solving the same problem of BMI calculation, show distinct implementation styles and coding practices. Key differences include variable type choices, input handling methods, code structure, and BMI category thresholds, indicating they were likely developed independently by different programmers approaching the same task.
+"import java.util.Scanner; public class T3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Prompt the user to enter weight in pounds System.out.print(""Enter weight in pounds: ""); double weight = input.nextDouble(); // Prompt the user to enter height System.out.print(""Enter feet: ""); double feet = input.nextDouble(); System.out.print(""Enter inches: ""); double inches = input.nextDouble(); double height = feet * 12 + inches; // Compute BMI double bmi = weight * 0.45359237 / ((height * 0.0254) * (height * 0.0254)); // Display result System.out.println(""BMI is "" + bmi); if (bmi < 18.5) System.out.println(""Underweight""); else if (bmi < 25) System.out.println(""Normal""); else if (bmi < 30) System.out.println(""Overweight""); else System.out.println(""Obese""); } }" "import java.util.Scanner; public class L1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(""Enter weight in pounds: ""); double weight = input.nextDouble(); System.out.print(""Enter feet: ""); double feet = input.nextDouble(); System.out.print(""Enter inches: ""); double inches = input.nextDouble(); double height = feet * 12 + inches; double bmi = weight * 0.45359237 / ((height * 0.0254) * (height * 0.0254)); System.out.println(""BMI is "" + bmi); if (bmi < 18.5) { System.out.println(""Underweight""); } else if (bmi < 25) { System.out.println(""Normal""); } else if (bmi < 30) { System.out.println(""Overweight""); } else { System.out.println(""Obese""); } } }" True The two code samples are nearly identical in structure, logic, variable names, and even specific constants used, with only minor differences in formatting and class names. This level of similarity is extremely unlikely to occur independently and strongly indicates that one sample was copied from the other or both were derived from a common source.
+"import java.util.Scanner; public class T3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Prompt the user to enter weight in pounds System.out.print(""Enter weight in pounds: ""); double weight = input.nextDouble(); // Prompt the user to enter height System.out.print(""Enter feet: ""); double feet = input.nextDouble(); System.out.print(""Enter inches: ""); double inches = input.nextDouble(); double height = feet * 12 + inches; // Compute BMI double bmi = weight * 0.45359237 / ((height * 0.0254) * (height * 0.0254)); // Display result System.out.println(""BMI is "" + bmi); if (bmi < 18.5) System.out.println(""Underweight""); else if (bmi < 25) System.out.println(""Normal""); else if (bmi < 30) System.out.println(""Overweight""); else System.out.println(""Obese""); } }" "import java.util.*; public class L2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print(""Enter weight in pounds: ""); double berat = sc.nextDouble(); System.out.print(""Enter feet: ""); double feet = sc.nextDouble(); System.out.print(""Enter inches: ""); double inci = sc.nextDouble(); double tinggi = feet * 12 + inci; double bmi = berat * 0.45359237 / ((tinggi * 0.0254) * (tinggi * 0.0254)); System.out.println(""BMI is "" + bmi); if (bmi < 18.5) { System.out.println(""Underweight""); } else if (bmi < 25) { System.out.println(""Normal""); } else if (bmi < 30) { System.out.println(""Overweight""); } else { System.out.println(""Obese""); } } }" True The two code samples exhibit nearly identical structure, logic, and functionality for calculating BMI, including the same input prompts, conversion factors, calculations, and output categories. While there are minor differences in variable names and formatting, these superficial changes do not alter the fact that the core implementation is essentially the same in both samples, strongly indicating plagiarism.
+"import java.util.Scanner; public class T3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Prompt the user to enter weight in pounds System.out.print(""Enter weight in pounds: ""); double weight = input.nextDouble(); // Prompt the user to enter height System.out.print(""Enter feet: ""); double feet = input.nextDouble(); System.out.print(""Enter inches: ""); double inches = input.nextDouble(); double height = feet * 12 + inches; // Compute BMI double bmi = weight * 0.45359237 / ((height * 0.0254) * (height * 0.0254)); // Display result System.out.println(""BMI is "" + bmi); if (bmi < 18.5) System.out.println(""Underweight""); else if (bmi < 25) System.out.println(""Normal""); else if (bmi < 30) System.out.println(""Overweight""); else System.out.println(""Obese""); } }" "import java.util.*; public class L3 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); double berat = 0; double inci = 0; double tinggi = 0 ; double bmi = 0; double feet = 0; System.out.print(""Enter weight in pounds: ""); berat = sc.nextDouble(); System.out.print(""Enter feet: ""); feet = sc.nextDouble(); System.out.print(""Enter inches: ""); inci = sc.nextDouble(); tinggi = feet * 12 + inci; bmi = berat * 0.45359237 / ((tinggi * 0.0254) * (tinggi * 0.0254)); System.out.println(""BMI is "" + bmi); if (bmi < 18.5) { System.out.println(""Underweight""); } else if (bmi < 25) { System.out.println(""Normal""); } else if (bmi < 30) { System.out.println(""Overweight""); } else { System.out.println(""Obese""); } } }" True The two code samples exhibit striking similarities in structure, logic, and even specific implementation details like the BMI calculation formula and classification thresholds, suggesting that one was likely derived from the other or both from a common source. While there are minor differences in variable names and formatting, the overall approach, user prompts, and output messages are nearly identical, indicating a high probability of code plagiarism rather than independent development.
+"import java.util.Scanner; public class T3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Prompt the user to enter weight in pounds System.out.print(""Enter weight in pounds: ""); double weight = input.nextDouble(); // Prompt the user to enter height System.out.print(""Enter feet: ""); double feet = input.nextDouble(); System.out.print(""Enter inches: ""); double inches = input.nextDouble(); double height = feet * 12 + inches; // Compute BMI double bmi = weight * 0.45359237 / ((height * 0.0254) * (height * 0.0254)); // Display result System.out.println(""BMI is "" + bmi); if (bmi < 18.5) System.out.println(""Underweight""); else if (bmi < 25) System.out.println(""Normal""); else if (bmi < 30) System.out.println(""Overweight""); else System.out.println(""Obese""); } }" "import java.util.*; public class L4 { public static double hitBmi(double berat, double tinggi) { return berat * 0.45359237 / ((tinggi * 0.0254) * (tinggi * 0.0254)); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); double berat = 0; double inci = 0; double tinggi = 0 ; double feet = 0; System.out.print(""Enter weight in pounds: ""); berat = sc.nextDouble(); System.out.print(""Enter feet: ""); feet = sc.nextDouble(); System.out.print(""Enter inches: ""); inci = sc.nextDouble(); tinggi = feet * 12 + inci; System.out.println(""BMI is "" + hitBmi(berat,tinggi)); if (hitBmi(berat,tinggi) < 18.5) { System.out.println(""Underweight""); } else if (hitBmi(berat,tinggi) < 25) { System.out.println(""Normal""); } else if (hitBmi(berat,tinggi) < 30) { System.out.println(""Overweight""); } else { System.out.println(""Obese""); } } }" True The two code samples exhibit striking similarities in overall structure, logic flow, and specific implementation details, including identical user prompts, BMI calculation formula, and categorization thresholds. While minor differences exist in variable naming and method organization, the extent of matching elements, particularly in the user interface and core algorithm, strongly suggests that one code sample was derived from the other or both were based on a common source.
+"import java.util.Scanner; public class T3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Prompt the user to enter weight in pounds System.out.print(""Enter weight in pounds: ""); double weight = input.nextDouble(); // Prompt the user to enter height System.out.print(""Enter feet: ""); double feet = input.nextDouble(); System.out.print(""Enter inches: ""); double inches = input.nextDouble(); double height = feet * 12 + inches; // Compute BMI double bmi = weight * 0.45359237 / ((height * 0.0254) * (height * 0.0254)); // Display result System.out.println(""BMI is "" + bmi); if (bmi < 18.5) System.out.println(""Underweight""); else if (bmi < 25) System.out.println(""Normal""); else if (bmi < 30) System.out.println(""Overweight""); else System.out.println(""Obese""); } }" "import java.util.*; public class L5 { public static double hitBmi(double berat, double tinggi) { return berat * 0.45359237 / ((tinggi * 0.0254) * (tinggi * 0.0254)); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); double berat, inci, tinggi, feet = 0; System.out.print(""Enter weight in pounds: ""); berat = sc.nextDouble(); System.out.print(""Enter feet: ""); feet = sc.nextDouble(); System.out.print(""Enter inches: ""); inci = sc.nextDouble(); tinggi = feet * 12 + inci; System.out.println(""BMI is "" + hitBmi(berat, tinggi)); if (hitBmi(berat, tinggi) < 18.5) { System.out.println(""Underweight""); } else if (hitBmi(berat, tinggi) < 25) { System.out.println(""Normal""); } else if (hitBmi(berat, tinggi) < 30) { System.out.println(""Overweight""); } else { System.out.println(""Obese""); } } }" True The two code samples exhibit significant structural and logical similarities, including identical BMI calculation formulas, input methods, and classification thresholds, which are unlikely to occur independently. However, there are also notable differences in variable naming, code organization, and styling, suggesting that if one code was derived from the other, it was modified rather than directly copied.
+"import java.util.Scanner; public class T3 { public static void main(String[] args) { Scanner input = new Scanner(System.in); // Prompt the user to enter weight in pounds System.out.print(""Enter weight in pounds: ""); double weight = input.nextDouble(); // Prompt the user to enter height System.out.print(""Enter feet: ""); double feet = input.nextDouble(); System.out.print(""Enter inches: ""); double inches = input.nextDouble(); double height = feet * 12 + inches; // Compute BMI double bmi = weight * 0.45359237 / ((height * 0.0254) * (height * 0.0254)); // Display result System.out.println(""BMI is "" + bmi); if (bmi < 18.5) System.out.println(""Underweight""); else if (bmi < 25) System.out.println(""Normal""); else if (bmi < 30) System.out.println(""Overweight""); else System.out.println(""Obese""); } }" "import java.util.*; public class L6 { public static double hitBmi(double berat, double tinggi) { return berat * 0.45359237 / ((tinggi * 0.0254) * (tinggi * 0.0254)); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); double berat, inci, tinggi, feet = 0; System.out.print(""Enter weight in pounds: ""); berat = sc.nextDouble(); System.out.print(""Enter feet: ""); feet = sc.nextDouble(); System.out.print(""Enter inches: ""); inci = sc.nextDouble(); tinggi = feet * 12 + inci; System.out.println(""BMI is "" + hitBmi(berat, tinggi)); if (hitBmi(berat, tinggi) < 25 && hitBmi(berat, tinggi) > 18.5) { System.out.println(""Normal""); } else if (hitBmi(berat, tinggi) < 30 && hitBmi(berat, tinggi) > 25) { System.out.println(""Overweight""); } else if (hitBmi(berat, tinggi) > 30) { System.out.println(""Obese""); } else { System.out.println(""Underweight""); } } }" True The two code samples share significant structural similarities, including identical input prompts, BMI calculation formulas, and output formats, which strongly suggest that one was derived from the other. However, the second sample shows evidence of modification, such as translated variable names and a reorganized code structure with a separate function for BMI calculation, indicating it's not a direct copy but rather a closely inspired adaptation.
+"public class T4 { public static void main(String[] args) { System.out.println(""Miles\t\tKilometers""); System.out.println(""-------------------------------""); // Use while loop int miles = 1; while (miles <= 10) { System.out.println(miles + ""\t\t"" + miles * 1.609); miles++; } } }" "/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author CB6AB3315634A1E4D11B091BA48B60BA 7E51EEA5FA101ED4DADE9AD3A7A072BB 2F809B10D1ABEDBF2EC288F851B3EBBB */ public class T04 { public static void main(String[] args){ System.out.println(""Miles\tKilometers""); for(int i = 1; i <= 10; i++){ System.out.printf(i + ""\t%.3f"", (i * 1.609)); System.out.println(); } } }" False The code samples share the same basic purpose and output format, which is expected given they solve the same problem of converting miles to kilometers. However, they differ significantly in implementation details such as loop structure, variable usage, output formatting, and overall code organization, suggesting they are likely independent solutions rather than a case of direct plagiarism.
+"public class T4 { public static void main(String[] args) { System.out.println(""Miles\t\tKilometers""); System.out.println(""-------------------------------""); // Use while loop int miles = 1; while (miles <= 10) { System.out.println(miles + ""\t\t"" + miles * 1.609); miles++; } } }" "/** * * @author 65FBEF05E01FAC390CB3FA073FB3E8CF (452BF208BF901322968557227B8F6EFE010) */ public class T04 { public static void main(String[] args) { System.out.println(""Miles Kilometers""); for (int i = 1; i <= 10; i++) { if (i == 10) { System.out.println(i + "" "" + i * 1609); } else { System.out.println(i + "" "" + i * 1609); } } } }" False The code samples share a common purpose of converting miles to kilometers, which is likely due to a shared assignment rather than plagiarism. However, the significant differences in implementation details, such as loop structure, variable usage, formatting, and even errors in calculation, strongly suggest these are independently developed solutions.
+"public class T4 { public static void main(String[] args) { System.out.println(""Miles\t\tKilometers""); System.out.println(""-------------------------------""); // Use while loop int miles = 1; while (miles <= 10) { System.out.println(miles + ""\t\t"" + miles * 1.609); miles++; } } }" "/** * * @author CB6AB3315634A1E4D11B091BA48B60BA */ public class Nomor4_2451041557A22145B3701B0184109CAB013 { /** * @param args the command line arguments */ public static void main(String[] args) { System.out.println(""Miles \t Kilometers""); for(int i = 1 ; i<=10;i++){ System.out.println(i+"" \t ""+i*1.069); } } }" False The two code samples share a common overall structure and purpose, which is expected given they're solving the same problem of converting miles to kilometers in a tabular format. However, they differ significantly in implementation details such as loop structure, variable naming, formatting choices, and even the conversion factor used, suggesting independent development rather than direct copying.
+"public class T4 { public static void main(String[] args) { System.out.println(""Miles\t\tKilometers""); System.out.println(""-------------------------------""); // Use while loop int miles = 1; while (miles <= 10) { System.out.println(miles + ""\t\t"" + miles * 1.609); miles++; } } }" "public class L1 { public static void main(String[] args) { System.out.println(""Miles\t\tKilometers""); System.out.println(""-------------------------------""); int miles = 1; while (miles <= 10) { System.out.println(miles + ""\t\t"" + miles * 1.609); miles++; } } }" True The two code samples are nearly identical in structure, logic, and implementation, with only superficial differences in class names and formatting. The matching content includes specific details like variable names, loop structure, and even the exact conversion factor (1.609), which is highly unlikely to occur independently and strongly indicates direct copying.
+"public class T4 { public static void main(String[] args) { System.out.println(""Miles\t\tKilometers""); System.out.println(""-------------------------------""); // Use while loop int miles = 1; while (miles <= 10) { System.out.println(miles + ""\t\t"" + miles * 1.609); miles++; } } }" "public class L2 { public static void main(String[] args) { System.out.println(""Miles\t\tKilometers""); System.out.println(""-------------------------------""); int mil = 1; while (mil <= 10) { System.out.println(mil + ""\t\t"" + mil * 1.609); mil++; } } }" True The code samples exhibit nearly identical structure, logic, and implementation details, including the same output formatting, loop structure, and calculation method. The only significant differences are superficial changes such as class names and variable names, which appear to be minimal alterations to an otherwise copied piece of code.
+"public class T4 { public static void main(String[] args) { System.out.println(""Miles\t\tKilometers""); System.out.println(""-------------------------------""); // Use while loop int miles = 1; while (miles <= 10) { System.out.println(miles + ""\t\t"" + miles * 1.609); miles++; } } }" "public class L3 { public static void main(String[] args) { int mil = 0 ; System.out.println(""Miles\t\tKilometers""); System.out.println(""-------------------------------""); mil = 1; while (mil <= 10) { System.out.println(mil + ""\t\t"" + mil * 1.609); mil++; } } }" True The two code samples exhibit nearly identical structure, logic, and output, with only superficial differences in class names, variable names, and formatting. Such a high degree of similarity, especially in the core implementation and specific details like the conversion factor used, strongly suggests that one sample was derived from the other with only minor alterations, which is indicative of plagiarism.
+"public class T4 { public static void main(String[] args) { System.out.println(""Miles\t\tKilometers""); System.out.println(""-------------------------------""); // Use while loop int miles = 1; while (miles <= 10) { System.out.println(miles + ""\t\t"" + miles * 1.609); miles++; } } }" "public class L4 { public static void print(int mil) { while (mil <= 10) { System.out.println(mil + ""\t\t"" + mil * 1.609); mil++; } } public static void main(String[] args) { int mil = 1 ; System.out.println(""Miles\t\tKilometers""); System.out.println(""-------------------------------""); print(mil); } }" True The two code samples are indeed plagiarized versions of each other because they share the exact same core logic, conversion factor, and output format, with only superficial changes in variable names, method structure, and formatting. The second sample appears to be an attempt to obfuscate the plagiarism by reorganizing the code and changing minor details, but the underlying algorithm and implementation remain fundamentally identical to the first sample.
+"public class T4 { public static void main(String[] args) { System.out.println(""Miles\t\tKilometers""); System.out.println(""-------------------------------""); // Use while loop int miles = 1; while (miles <= 10) { System.out.println(miles + ""\t\t"" + miles * 1.609); miles++; } } }" "public class L5 { public static void print(int mil) { for ( int i = 0 ; i < 10 ; i ++){ System.out.println(mil + ""\t\t"" + mil * 1.609); mil++; } } public static void main(String[] args) { int mil = 1 ; System.out.println(""Miles\t\tKilometers""); System.out.println(""-------------------------------""); print(mil); } }" True These code samples exhibit plagiarism due to their identical output formatting, conversion logic, and specific choices like the range of miles (1-10) and exact conversion factor (1.609). While there are surface-level differences in loop structure and method organization, the core implementation and output are too similar to be coincidental, strongly suggesting that one was derived from the other.
+"public class T4 { public static void main(String[] args) { System.out.println(""Miles\t\tKilometers""); System.out.println(""-------------------------------""); // Use while loop int miles = 1; while (miles <= 10) { System.out.println(miles + ""\t\t"" + miles * 1.609); miles++; } } }" "public class L6 { public static void print(int mil) { for ( int i = 10 ; i > 0 ; i --){ System.out.println(mil + ""\t\t"" + mil * 1.609); mil++; } } public static void main(String[] args) { int mil = 1 ; System.out.println(""Miles\t\tKilometers""); System.out.println(""-------------------------------""); print(mil); } }" True The two code samples are indeed plagiarized, primarily because they share identical core logic, output formatting, and conversion factors, with only superficial differences in loop structure and method organization. The second sample appears to be an attempt to disguise the plagiarism by rearranging code elements and changing variable names, but the fundamental algorithm and output remain the same, indicating that the code was likely copied and then slightly modified.
+"public class T5 { public static void main(String[] args) { System.out.print(""Enter an integer: ""); java.util.Scanner input = new java.util.Scanner(System.in); int number = input.nextInt(); reverse(number); } public static void reverse(int number) { while (number != 0) { int remainder = number % 10; System.out.print(remainder); number = number / 10; } System.out.println(); } }" "import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author CB6AB3315634A1E4D11B091BA48B60BA 7E51EEA5FA101ED4DADE9AD3A7A072BB 2F809B10D1ABEDBF2EC288F851B3EBBB */ public class T05 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); System.out.print(""Enter an integer: ""); int number = sc.nextInt(); reverse(number); } public static void reverse(int number){ while(number > 0){ System.out.print(number % 10); number /= 10; } System.out.println(); } }" False These code samples represent independent implementations of a common, straightforward programming exercise. While they share the same basic algorithm due to the simplicity of the task, the differences in implementation details, coding style, and structure indicate they were likely developed separately by different programmers.
+"public class T5 { public static void main(String[] args) { System.out.print(""Enter an integer: ""); java.util.Scanner input = new java.util.Scanner(System.in); int number = input.nextInt(); reverse(number); } public static void reverse(int number) { while (number != 0) { int remainder = number % 10; System.out.print(remainder); number = number / 10; } System.out.println(); } }" "import java.util.Scanner; /** * * @author 65FBEF05E01FAC390CB3FA073FB3E8CF (452BF208BF901322968557227B8F6EFE010) */ public class T05 { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.print(""Enter a integer: ""); int a = s.nextInt(); reverse(a); } public static void reverse(int number) { String temp=String.valueOf(number); for(int i=temp.length();i>0;i--){ System.out.print(temp.charAt(i-1)); } } }" False The two code samples have different implementations for the reverse method, with Sample 1 using modulo arithmetic and Sample 2 using string manipulation, indicating distinct approaches to solving the problem. Additionally, the coding styles, variable names, and overall structure differ sufficiently to suggest these are independent solutions rather than a case of direct copying.
+"public class T5 { public static void main(String[] args) { System.out.print(""Enter an integer: ""); java.util.Scanner input = new java.util.Scanner(System.in); int number = input.nextInt(); reverse(number); } public static void reverse(int number) { while (number != 0) { int remainder = number % 10; System.out.print(remainder); number = number / 10; } System.out.println(); } }" "import java.util.Scanner; /** * * @author CB6AB3315634A1E4D11B091BA48B60BA */ public class Nomor5_2451041557A22145B3701B0184109CAB013 { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print(""Enter an integer : ""); int number = sc.nextInt(); reverse(number); } public static void reverse(int number){ String strNumber = Integer.toString(number); String temp = """"; for(int i = strNumber.length(); i>0;i--){ temp +=i; } int tempNumber = Integer.parseInt(temp); System.out.println((tempNumber)); } }" False The core logic for reversing the number is fundamentally different between the two samples: the first uses a mathematical approach with modulo and division operations, while the second converts the number to a string and reverses it using string manipulation. Additionally, the implementation details, such as the loop structure and variable handling, are distinct enough to suggest independent development rather than copying.
+"public class T5 { public static void main(String[] args) { System.out.print(""Enter an integer: ""); java.util.Scanner input = new java.util.Scanner(System.in); int number = input.nextInt(); reverse(number); } public static void reverse(int number) { while (number != 0) { int remainder = number % 10; System.out.print(remainder); number = number / 10; } System.out.println(); } }" "public class L1 { public static void main(String[] args) { System.out.print(""Enter an integer: ""); java.util.Scanner input = new java.util.Scanner(System.in); int number = input.nextInt(); reverse(number); } public static void reverse(int number) { while (number != 0) { int remainder = number % 10; System.out.print(remainder); number = number / 10; } System.out.println(); } }" True The code samples are identical in structure, logic, variable names, and even formatting, with only the class names differing (T5 vs L1). Such a high degree of similarity, including identical implementation details and coding style, is extremely unlikely to occur independently and strongly indicates that one code sample was copied from the other or both were copied from a common source.
+"public class T5 { public static void main(String[] args) { System.out.print(""Enter an integer: ""); java.util.Scanner input = new java.util.Scanner(System.in); int number = input.nextInt(); reverse(number); } public static void reverse(int number) { while (number != 0) { int remainder = number % 10; System.out.print(remainder); number = number / 10; } System.out.println(); } }" "public class L2 { public static void main(String[] args) { System.out.print(""Enter an integer: ""); java.util.Scanner input = new java.util.Scanner(System.in); int nomor = input.nextInt(); balik(nomor); } public static void balik(int nomor) { while (nomor != 0) { int sisa = nomor % 10; System.out.print(sisa); nomor = nomor / 10; } System.out.println(); } }" True The two code samples are nearly identical in structure, logic, and implementation, with only superficial differences in naming conventions for classes, methods, and variables. This level of similarity, where even the algorithm and coding style are exactly the same, strongly indicates that one code sample was copied from the other with minimal alterations to disguise the plagiarism.
+"public class T5 { public static void main(String[] args) { System.out.print(""Enter an integer: ""); java.util.Scanner input = new java.util.Scanner(System.in); int number = input.nextInt(); reverse(number); } public static void reverse(int number) { while (number != 0) { int remainder = number % 10; System.out.print(remainder); number = number / 10; } System.out.println(); } }" "public class L3 { public static void main(String[] args) { int nomor = 0; System.out.print(""Enter an integer: ""); java.util.Scanner input = new java.util.Scanner(System.in); nomor = input.nextInt(); balik(nomor); } public static void balik(int nomor) { int sisa = 0 ; while (nomor != 0) { sisa = nomor % 10; System.out.print(sisa); nomor = nomor / 10; } System.out.println(); } }" True The two code samples exhibit nearly identical structure, logic, and algorithm for reversing an integer, with only superficial differences in naming conventions and minor implementation details. These similarities, combined with what appear to be deliberate attempts to disguise the code through minimal changes, strongly suggest that the second sample is derived from the first, indicating plagiarism.
+"public class T5 { public static void main(String[] args) { System.out.print(""Enter an integer: ""); java.util.Scanner input = new java.util.Scanner(System.in); int number = input.nextInt(); reverse(number); } public static void reverse(int number) { while (number != 0) { int remainder = number % 10; System.out.print(remainder); number = number / 10; } System.out.println(); } }" "public class L4 { public static void main(String[] args) { int nomor = 0; System.out.print(""Enter an integer: ""); java.util.Scanner input = new java.util.Scanner(System.in); nomor = input.nextInt(); int sisa = 0 ; while (nomor != 0) { sisa = nomor % 10; System.out.print(sisa); nomor = nomor / 10; } System.out.println(); } }" True The two code samples exhibit nearly identical logic, structure, and functionality for reversing an integer, including the same approach to input, digit extraction, and output. Despite minor differences in variable names and method organization, the core algorithm and even some verbatim code segments are so similar that it strongly suggests one sample was derived from the other or both from a common source, indicating likely plagiarism.
+"public class T5 { public static void main(String[] args) { System.out.print(""Enter an integer: ""); java.util.Scanner input = new java.util.Scanner(System.in); int number = input.nextInt(); reverse(number); } public static void reverse(int number) { while (number != 0) { int remainder = number % 10; System.out.print(remainder); number = number / 10; } System.out.println(); } }" "public class L5 { public static void main(String[] args) { int nomor, sisa = 0; System.out.print(""Enter an integer: ""); java.util.Scanner input = new java.util.Scanner(System.in); nomor = input.nextInt(); while (nomor!=0) { sisa = nomor % 10; System.out.print(sisa); nomor = nomor / 10; } System.out.println(); } }" True The two code samples share identical core logic for reversing a number, including the same algorithm structure and even identical lines of code for user input. While there are minor differences in variable names and method organization, the overwhelming similarities in implementation and problem-solving approach strongly indicate that one sample was derived from the other or both came from a common source.
+"public class T5 { public static void main(String[] args) { System.out.print(""Enter an integer: ""); java.util.Scanner input = new java.util.Scanner(System.in); int number = input.nextInt(); reverse(number); } public static void reverse(int number) { while (number != 0) { int remainder = number % 10; System.out.print(remainder); number = number / 10; } System.out.println(); } }" "public class L6_fix { public static void main(String[] args) { int nomor, sisa = 0; System.out.print(""Enter an integer: ""); java.util.Scanner input = new java.util.Scanner(System.in); nomor = input.nextInt(); while (nomor!=0) { if (nomor!=0){ sisa = nomor % 10; System.out.print(sisa); nomor = nomor / 10;} } System.out.println(); } }" True "The code samples exhibit plagiarism due to their identical input prompts, use of the full ""java.util.Scanner"" class name, and fundamentally identical logic for reversing integers using modulo and division operations. While superficial changes were made in variable names and method structure, the core implementation remains essentially the same, suggesting that the second sample (L6_fix) is a modified version of the first (T5) with attempts to disguise the copying."
+"public class T6 { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); int[] num = new int[10]; for (int i = 0; i < 10; i++) { // Read a number System.out.print(""Read a number: ""); num[i] = input.nextInt(); } // Display the array for (int i = 9; i >= 0; i--) { System.out.println(num[i]); } } }" "import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author CB6AB3315634A1E4D11B091BA48B60BA 7E51EEA5FA101ED4DADE9AD3A7A072BB 2F809B10D1ABEDBF2EC288F851B3EBBB */ public class T06 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int[] input = new int[10]; for(int i = 0; i < input.length; i++){ System.out.print(""Read a number: ""); input[i] = sc.nextInt(); } for(int i = 9; i >= 0; i--){ System.out.println(input[i]); } } }" False Upon closer examination, these code samples are not instances of plagiarism, but rather independent solutions to a common programming problem. The similarities can be attributed to standard Java syntax, typical beginner coding patterns, and likely shared problem specifications, while the differences in implementation details and structure indicate distinct authorship.
+"public class T6 { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); int[] num = new int[10]; for (int i = 0; i < 10; i++) { // Read a number System.out.print(""Read a number: ""); num[i] = input.nextInt(); } // Display the array for (int i = 9; i >= 0; i--) { System.out.println(num[i]); } } }" "import java.util.Scanner; /** * * @author 65FBEF05E01FAC390CB3FA073FB3E8CF (452BF208BF901322968557227B8F6EFE010) */ public class T06 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int[] a=new int[10]; for(int i=0;i<10;i++){ System.out.print(""Read a number: ""); a[i]=s.nextInt(); } for(int i=9;i>=0;i--){ System.out.println(a[i]); } } }" False Basic programming exercises often lead to similar solutions, especially when dealing with fundamental concepts like array manipulation and input/output operations in Java. The similarities between these two code samples are more likely due to the nature of the problem and the constraints of the Java language, rather than plagiarism, as both implement a common beginner's task of reading and reversing a fixed number of inputs using standard programming constructs.
+"public class T6 { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); int[] num = new int[10]; for (int i = 0; i < 10; i++) { // Read a number System.out.print(""Read a number: ""); num[i] = input.nextInt(); } // Display the array for (int i = 9; i >= 0; i--) { System.out.println(num[i]); } } }" "import java.util.Scanner; /** * * @author CB6AB3315634A1E4D11B091BA48B60BA */ public class Nomor6_2451041557A22145B3701B0184109CAB013 { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int Array[] = new int[10]; for(int i = 0 ; i<10;i++){ System.out.print(""Read a number: ""); Array[i] = sc.nextInt(); } for(int i = 9 ; i >= 0 ; i--){ System.out.println(Array[i]); } } }" False These code samples are not plagiarism because they're solutions to a common beginner programming problem with limited implementation options in Java. The similarities stem from standard Java conventions and the problem's constraints, not from copying. Despite structural parallels, differences in class names, variable naming, and code style indicate independent development by different individuals solving the same basic task.
+"public class T6 { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); int[] num = new int[10]; for (int i = 0; i < 10; i++) { // Read a number System.out.print(""Read a number: ""); num[i] = input.nextInt(); } // Display the array for (int i = 9; i >= 0; i--) { System.out.println(num[i]); } } }" "public class L1 { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); int[] num = new int[10]; for (int i = 0; i < 10; i++) { System.out.print(""Read a number: ""); num[i] = input.nextInt(); } for (int i = 9; i >= 0; i--) { System.out.println(num[i]); } } }" True The code samples are nearly identical in structure, logic, and functionality, with only trivial differences in class names and formatting. Such a high degree of similarity, especially in variable names, loop structures, and even the specific input prompt wording, is extremely unlikely to occur independently and strongly indicates that one code sample was directly copied from the other with minimal alterations.
+"public class T6 { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); int[] num = new int[10]; for (int i = 0; i < 10; i++) { // Read a number System.out.print(""Read a number: ""); num[i] = input.nextInt(); } // Display the array for (int i = 9; i >= 0; i--) { System.out.println(num[i]); } } }" "public class L2_6 { public static void main(String[] args) { java.util.Scanner sc = new java.util.Scanner(System.in); int[] angka = new int[10]; for (int i = 0; i < 10; i++) { System.out.print(""Read a number: ""); angka[i] = sc.nextInt(); } for (int i = 9; i >= 0; i--) { System.out.println(angka[i]); } } }" True The code samples exhibit nearly identical structure, logic, and implementation, including the same array size, input method, loop structures, and even the same input prompt. While variable and class names differ slightly, these minor changes are insufficient to disguise the overwhelming similarities in the core functionality and coding approach, strongly suggesting that one sample was derived from the other or both from a common source.
+"public class T6 { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); int[] num = new int[10]; for (int i = 0; i < 10; i++) { // Read a number System.out.print(""Read a number: ""); num[i] = input.nextInt(); } // Display the array for (int i = 9; i >= 0; i--) { System.out.println(num[i]); } } }" "import java.util.*; public class L3 { public static void main(String[] args) { int[] angka = new int[10]; Scanner sc = new java.util.Scanner(System.in); for (int i = 0; i < 10; i++) { System.out.print(""Read a number: ""); angka[i] = sc.nextInt(); } for (int i = 9; i >= 0; i--) { System.out.println(angka[i]); } } }" True The two code samples exhibit identical logic, structure, and functionality, with only superficial differences in variable names and minor formatting. The level of similarity in the implementation details, including the exact loop structures and output logic, strongly suggests that one code sample was derived from the other with minimal alterations, rather than being independently developed.
+"public class T6 { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); int[] num = new int[10]; for (int i = 0; i < 10; i++) { // Read a number System.out.print(""Read a number: ""); num[i] = input.nextInt(); } // Display the array for (int i = 9; i >= 0; i--) { System.out.println(num[i]); } } }" "import java.util.*; public class L4 { public static void print (int [] arr) { for (int i = 9; i >= 0; i--) { System.out.println(arr[i]); } } public static void main(String[] args) { int[] angka = new int[10]; Scanner sc = new java.util.Scanner(System.in); for (int i = 0; i < 10; i++) { System.out.print(""Read a number: ""); angka[i] = sc.nextInt(); } print(angka); } }" True The two code samples share identical core logic, including the exact same user prompt and reverse array printing mechanism, which is unlikely to occur independently. While there are minor differences in structure and naming, these appear to be surface-level changes that don't alter the fundamental approach, suggesting one solution was likely derived from or heavily influenced by the other.
+"public class T6 { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); int[] num = new int[10]; for (int i = 0; i < 10; i++) { // Read a number System.out.print(""Read a number: ""); num[i] = input.nextInt(); } // Display the array for (int i = 9; i >= 0; i--) { System.out.println(num[i]); } } }" "import java.util.*; public class L5 { public static void print(int[] arr) { int i = 9; while (i >= 0) { System.out.println(arr[i]); i--; } } public static void main(String[] args) { int[] angka = new int[10]; Scanner sc = new java.util.Scanner(System.in); int i = 0; while (i != 10) { System.out.print(""Read a number: ""); angka[i] = sc.nextInt(); i++; } print(angka); } }" True "These code samples exhibit clear signs of plagiarism due to their identical core logic, specific implementation choices, and the use of the exact same unique input prompt ""Read a number: "". While there are superficial differences in loop structures and method organization, these appear to be attempts to disguise the copying rather than indications of independent work."
+"public class T6 { public static void main(String[] args) { java.util.Scanner input = new java.util.Scanner(System.in); int[] num = new int[10]; for (int i = 0; i < 10; i++) { // Read a number System.out.print(""Read a number: ""); num[i] = input.nextInt(); } // Display the array for (int i = 9; i >= 0; i--) { System.out.println(num[i]); } } }" "import java.util.*; public class L6 { public static void print(int[] arr) { int i = 9; int j = 0; while (j < 10) { System.out.println(arr[i]); i--; j++; } } public static void main(String[] args) { int[] angka = new int[10]; Scanner sc = new java.util.Scanner(System.in); int i = 0; while (i != 10) { System.out.print(""Read a number: ""); angka[i] = sc.nextInt(); i++; } print(angka); } }" True The two code samples exhibit clear signs of plagiarism due to their nearly identical structure, logic, and even specific text elements like the input prompt. While Sample 2 attempts to disguise the copying through superficial changes such as different loop types and method organization, the core solution remains fundamentally the same, indicating that one was derived from the other or both from a common source.
+"import java.util.Scanner; public class T7 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(""Enter a 4 by 4 matrix row by row: ""); double[][] m = new double[4][4]; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) m[i][j] = input.nextDouble(); System.out.print(""Sum of the elements in the major diagonal is "" + sumMajorDiagonal(m)); } public static double sumMajorDiagonal(double[][] m) { double sum = 0; for (int i = 0; i < m.length; i++) sum += m[i][i]; return sum; } }" "import java.util.Scanner; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author CB6AB3315634A1E4D11B091BA48B60BA 7E51EEA5FA101ED4DADE9AD3A7A072BB 2F809B10D1ABEDBF2EC288F851B3EBBB */ public class T07 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); double[][] m = new double[4][4]; System.out.println(""Enter a 4-by-4 matrix row by row: ""); for(int i = 0; i < m.length; i++){ for(int j = 0; j < m[0].length; j++){ m[i][j] = sc.nextDouble(); } } System.out.println(""Sum of the elements in the major diagonal is "" + sumMajorDiagonal(m)); } public static double sumMajorDiagonal(double[][] m){ double sum = 0; for(int i = 0; i < m.length; i++){ sum += m[i][i]; } return sum; } }" False While the code samples share similarities due to addressing the same problem (summing the major diagonal of a 4x4 matrix), they exhibit differences in implementation details, coding style, and variable naming conventions that suggest independent development rather than direct plagiarism.
+"import java.util.Scanner; public class T7 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(""Enter a 4 by 4 matrix row by row: ""); double[][] m = new double[4][4]; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) m[i][j] = input.nextDouble(); System.out.print(""Sum of the elements in the major diagonal is "" + sumMajorDiagonal(m)); } public static double sumMajorDiagonal(double[][] m) { double sum = 0; for (int i = 0; i < m.length; i++) sum += m[i][i]; return sum; } }" "import java.util.Scanner; /** * * @author 65FBEF05E01FAC390CB3FA073FB3E8CF (452BF208BF901322968557227B8F6EFE010) */ public class T07 { public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.println(""Enter a 4-by-4 matrix row by row:""); double[][] m=new double[4][4]; for(int i=0;i<4;i++){ for(int j=0;j<4;j++){ m[i][j]=s.nextDouble(); } } System.out.println(""Sum of the elements in the major diagonal is ""+sumMajorDiagonal(m)); } public static double sumMajorDiagonal(double[][] m){ double temp=0; for(int i=0;i<4;i++){ for(int j=0;j<4;j++){ if(i==j){ temp=temp+m[i][j]; } } } return temp; } }" False The code samples show significant differences in implementation details, particularly in the sumMajorDiagonal method, and in coding style, suggesting independent problem-solving approaches rather than direct copying. While there are similarities in overall structure and problem statement, these are largely expected given the specific nature of the programming task and the constraints of the Java language.
+"import java.util.Scanner; public class T7 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(""Enter a 4 by 4 matrix row by row: ""); double[][] m = new double[4][4]; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) m[i][j] = input.nextDouble(); System.out.print(""Sum of the elements in the major diagonal is "" + sumMajorDiagonal(m)); } public static double sumMajorDiagonal(double[][] m) { double sum = 0; for (int i = 0; i < m.length; i++) sum += m[i][i]; return sum; } }" "import java.util.Scanner; /** * * @author ASUS */ public class Nomor7_2451041557A22145B3701B0184109CAB013 { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int [][] matrix = new int [4][4]; int sum =0; System.out.println(""Enter a 4-by-4 matrix row by row: ""); for(int i =0 ;i<4;i++){ for(int j=0;j<4;j++){ matrix[i][j]= sc.nextInt(); if(i==j){ sum += matrix[i][j]; } } } System.out.println(""Sum of the elements in the major diagonal is ""+sum); } }" False These code samples are not plagiarism because they use distinctly different implementations to solve the same problem, including separate methods vs. inline calculation, different data types, and unique looping structures. While they share the common goal of summing a matrix's diagonal, the differences in coding style, variable names, and overall structure indicate they are independent solutions to a standard programming exercise.
+"import java.util.Scanner; public class T7 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(""Enter a 4 by 4 matrix row by row: ""); double[][] m = new double[4][4]; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) m[i][j] = input.nextDouble(); System.out.print(""Sum of the elements in the major diagonal is "" + sumMajorDiagonal(m)); } public static double sumMajorDiagonal(double[][] m) { double sum = 0; for (int i = 0; i < m.length; i++) sum += m[i][i]; return sum; } }" "import java.util.*; public class L1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(""Enter a 4 by 4 matrix row by row: ""); double[][] m = new double[4][4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { m[i][j] = input.nextDouble(); } } System.out.print(""Sum of the elements in the major diagonal is "" + sumMajorDiagonal(m)); } public static double sumMajorDiagonal(double[][] m) { double sum = 0; for (int i = 0; i < m.length; i++) { sum += m[i][i]; } return sum; } }" True The two code samples have nearly identical structure, logic, and even verbatim text in comments and output statements, with only minor differences in formatting and class names. This level of similarity is highly unlikely to occur independently and strongly indicates that one sample was copied from the other with minimal changes, or both were derived from a common source.
+"import java.util.Scanner; public class T7 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(""Enter a 4 by 4 matrix row by row: ""); double[][] m = new double[4][4]; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) m[i][j] = input.nextDouble(); System.out.print(""Sum of the elements in the major diagonal is "" + sumMajorDiagonal(m)); } public static double sumMajorDiagonal(double[][] m) { double sum = 0; for (int i = 0; i < m.length; i++) sum += m[i][i]; return sum; } }" "import java.util.*; public class L2 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print(""Enter a 4 by 4 matrix row by row: ""); double[][] m = new double[4][4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { m[i][j] = sc.nextDouble(); } } System.out.print(""Sum of the elements in the major diagonal is "" + jumlahDiagonal(m)); } public static double jumlahDiagonal(double[][] m) { double sum = 0; for (int i = 0; i < m.length; i++) { sum += m[i][i]; } return sum; } }" True These code samples exhibit plagiarism due to their nearly identical structure, logic, and implementation, including matching user prompts, matrix handling, and diagonal sum calculation methods. The minimal differences, such as variable names and formatting, appear to be superficial attempts to disguise the copying, rather than evidence of independent problem-solving approaches.
+"import java.util.Scanner; public class T7 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(""Enter a 4 by 4 matrix row by row: ""); double[][] m = new double[4][4]; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) m[i][j] = input.nextDouble(); System.out.print(""Sum of the elements in the major diagonal is "" + sumMajorDiagonal(m)); } public static double sumMajorDiagonal(double[][] m) { double sum = 0; for (int i = 0; i < m.length; i++) sum += m[i][i]; return sum; } }" "import java.util.*; public class L3 { public static double jumlahDiagonal(double[][] m) { double sum = 0; for (int i = 0; i < m.length; i++) { sum += m[i][i]; } return sum; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); double[][] m = new double[4][4]; System.out.print(""Enter a 4 by 4 matrix row by row: ""); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { m[i][j] = sc.nextDouble(); } } System.out.print(""Sum of the elements in the major diagonal is "" + jumlahDiagonal(m)); } }" True The two code samples exhibit nearly identical structure, logic, and implementation for solving the same problem, with only minor differences in variable names and method naming. The high degree of similarity in both the overall approach and specific code details, including the exact same matrix size and input prompts, strongly suggests that one sample was derived from the other with only superficial modifications.
+"import java.util.Scanner; public class T7 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(""Enter a 4 by 4 matrix row by row: ""); double[][] m = new double[4][4]; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) m[i][j] = input.nextDouble(); System.out.print(""Sum of the elements in the major diagonal is "" + sumMajorDiagonal(m)); } public static double sumMajorDiagonal(double[][] m) { double sum = 0; for (int i = 0; i < m.length; i++) sum += m[i][i]; return sum; } }" "import java.util.*; public class L4 { public static double jumlahDiagonal(double[][] m) { double sum = 0; for (int i = 0; i < m.length; i++) { sum += m[i][i]; } return sum; } public static void print(double[][] m) { System.out.print(""Sum of the elements in the major diagonal is "" + jumlahDiagonal(m)); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); double[][] m = new double[4][4]; System.out.println(""Enter a 4 by 4 matrix row by row: ""); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { m[i][j] = sc.nextDouble(); } } print(m); } }" True The two code samples exhibit nearly identical logic, structure, and even wording in output messages, which is highly unlikely to occur independently. While there are minor differences in naming and code organization, the core implementation - especially the method for summing the diagonal elements - is almost exactly the same, strongly suggesting that one sample was derived from the other or both were derived from a common source.
+"import java.util.Scanner; public class T7 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(""Enter a 4 by 4 matrix row by row: ""); double[][] m = new double[4][4]; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) m[i][j] = input.nextDouble(); System.out.print(""Sum of the elements in the major diagonal is "" + sumMajorDiagonal(m)); } public static double sumMajorDiagonal(double[][] m) { double sum = 0; for (int i = 0; i < m.length; i++) sum += m[i][i]; return sum; } }" "import java.util.*; public class L5 { public static double jumlahDiagonal(double[][] m) { double sum = 0; int hit = 0; while (hit != m.length) { sum += m[hit][hit]; hit++; } return sum; } public static void print(double[][] m) { System.out.print(""Sum of the elements in the major diagonal is "" + jumlahDiagonal(m)); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); double[][] m = new double[4][4]; System.out.println(""Enter a 4 by 4 matrix row by row: ""); for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { m[i][j] = sc.nextDouble(); } } print(m); } }" True These code samples represent clear plagiarism despite superficial attempts to disguise it. The core algorithm, problem-solving approach, and even specific output formatting are identical, revealing that one sample was directly copied from the other. The minor changes made, such as renaming variables and altering loop structures, are typical tactics used to mask plagiarism but do not change the fundamental similarity of the code.
+"import java.util.Scanner; public class T7 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print(""Enter a 4 by 4 matrix row by row: ""); double[][] m = new double[4][4]; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) m[i][j] = input.nextDouble(); System.out.print(""Sum of the elements in the major diagonal is "" + sumMajorDiagonal(m)); } public static double sumMajorDiagonal(double[][] m) { double sum = 0; for (int i = 0; i < m.length; i++) sum += m[i][i]; return sum; } }" "import java.util.*; public class L6 { public static double jumlahDiagonal(double[][] m) { double sum = 0; int hit = m.length-1; while (hit >= 0) { sum += m[hit][hit]; hit--; } return sum; } public static void print(double[][] m) { System.out.print(""Sum of the elements in the major diagonal is "" + jumlahDiagonal(m)); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); double[][] m = new double[4][4]; System.out.println(""Enter a 4 by 4 matrix row by row: ""); for (int i = 3; i >= 0 ; i--) { for (int j = 3; j >= 0; j--) { m[i][j] = sc.nextDouble(); } } print(m); } }" True These code samples show clear signs of plagiarism despite superficial differences. The overall structure, problem approach, and key phrases (like input and output messages) are nearly identical, indicating the second sample was likely derived from the first. The changes made, such as different method names and loop directions, appear to be attempts to disguise the plagiarism rather than evidence of independent implementation.