website/static/~brozek/index.html?labaide%2Fspring2018%2Fcpsc220%2Fmidtermreview.html
2022-02-15 01:14:58 -05:00

102 lines
3.1 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="author" content="Brandon Rozek">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="robots" content="noindex" />
<title>Brandon Rozek</title>
<link rel="stylesheet" href="themes/bitsandpieces/styles/main.css" type="text/css" />
<link rel="stylesheet" href="themes/bitsandpieces/styles/highlightjs-github.css" type="text/css" />
</head>
<body>
<aside class="main-nav">
<nav>
<ul>
<li class="menuitem ">
<a href="index.html%3Findex.html" data-shortcut="">
Home
</a>
</li>
<li class="menuitem ">
<a href="index.html%3Fcourses.html" data-shortcut="">
Courses
</a>
</li>
<li class="menuitem ">
<a href="index.html%3Flabaide.html" data-shortcut="">
Lab Aide
</a>
</li>
<li class="menuitem ">
<a href="index.html%3Fpresentations.html" data-shortcut="">
Presentations
</a>
</li>
<li class="menuitem ">
<a href="index.html%3Fresearch.html" data-shortcut="">
Research
</a>
</li>
<li class="menuitem ">
<a href="index.html%3Ftranscript.html" data-shortcut="">
Transcript
</a>
</li>
</ul>
</nav>
</aside>
<main class="main-content">
<article class="article">
<h1>More Midterm Review</h1>
<p>Let us suppose that we have the following array</p>
<pre><code class="language-java">int[] b = {11, 12, 15, 16, 21}</code></pre>
<h2>Increase all elements by 2</h2>
<pre><code class="language-java">for (int i = 0; i &lt; b.length; i++) {
b[i] += 2;
}</code></pre>
<h2>Print all elements of array</h2>
<pre><code class="language-java">for (int i = 0; i &lt; b.length; i++) {
System.out.println(b[i]);
}</code></pre>
<h2>Sum all the elements of an array</h2>
<pre><code class="language-java">int sum = 0;
for (int i = 0; i &lt; b.length; i++) {
sum += b[i];
}</code></pre>
<h2>Access Last Element of Array</h2>
<pre><code class="language-java">System.out.println(b[b.length - 1]);</code></pre>
<h2>Access the middle element</h2>
<pre><code class="language-java">System.out.println(b[b.length / 2]);</code></pre>
</article>
</main>
<script src="themes/bitsandpieces/scripts/highlight.js"></script>
<script src="themes/bitsandpieces/scripts/mousetrap.min.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
processEscapes: true
}
});
</script>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script>
hljs.initHighlightingOnLoad();
document.querySelectorAll('.menuitem a').forEach(function(el) {
if (el.getAttribute('data-shortcut').length > 0) {
Mousetrap.bind(el.getAttribute('data-shortcut'), function() {
location.assign(el.getAttribute('href'));
});
}
});
</script>
</body>
</html>