57 lines
2.8 KiB
HTML
57 lines
2.8 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
<html>
|
|
<head>
|
|
<title>ArrayCopy2.java</title>
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
|
<style type="text/css">
|
|
<!--
|
|
body {color: #000000; background-color: #ffffff; font-family: monospace}
|
|
pre {color: #000000; background-color: #ffffff; font-family: monospace}
|
|
table {color: #404040; background-color: #e9e8e2; font-family: monospace}
|
|
.ST0 {color: #969696; font-family: monospace; font-weight: bold}
|
|
.comment {color: #969696}
|
|
.string {color: #1e9347}
|
|
.literal {color: #336bdd}
|
|
-->
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab16_arrays2_CalebFontenot/src/main/java/com/calebfontenot/lab16_arrays2_calebfontenot/ArrayCopy2.java</td></tr></table>
|
|
<pre>
|
|
<span class="comment">/*</span>
|
|
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
|
|
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
|
|
<span class="comment"> */</span>
|
|
<span class="literal">package</span> com.calebfontenot.lab16_arrays2_calebfontenot;
|
|
|
|
<span class="comment">/**</span>
|
|
<span class="comment"> *</span>
|
|
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">caleb</span>
|
|
<span class="comment">*/</span>
|
|
<span class="literal">public</span> <span class="literal">class</span> ArrayCopy2 {
|
|
|
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
|
|
{
|
|
<span class="literal">int</span>[] sourceArray = {1, 2, 3, 4, 5};
|
|
<span class="literal">int</span>[] targetArray = <span class="literal">new</span> <span class="literal">int</span>[sourceArray.length];
|
|
<span class="comment">// Print the source array</span>
|
|
<span class="literal">for</span> (<span class="literal">int</span> i = 0; i < sourceArray.length; i++) {
|
|
System.out.print(sourceArray[i] + <span class="string">"</span> <span class="string">"</span>);
|
|
}
|
|
System.out.println();
|
|
<span class="comment">// Copy the source array to the target array in reversed order</span>
|
|
<span class="literal">int</span> j = (sourceArray.length - 1);
|
|
<span class="literal">for</span> (<span class="literal">int</span> i = 0; i < sourceArray.length; i++) {
|
|
targetArray[i] = sourceArray[j];
|
|
j--;
|
|
}
|
|
<span class="comment">// Print the target array</span>
|
|
<span class="literal">for</span> (<span class="literal">int</span> i = 0; i < sourceArray.length; i++) {
|
|
System.out.print(targetArray[i] + <span class="string">"</span> <span class="string">"</span>);
|
|
}
|
|
}
|
|
}
|
|
|
|
</pre></body>
|
|
</html>
|