<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5915261747998938651</id><updated>2025-02-11T00:19:58.509+05:30</updated><category term="Page Replacement"/><category term="java algorithms"/><category term="SPOS"/><category term="SPOS lab"/><category term="SQL"/><category term="TABLES"/><category term="assembler directives"/><category term="macro processor"/><category term="system programming"/><category term="Array"/><category term="JAVA"/><category term="JOINS"/><category term="Merge Sort"/><category term="Quick Sort"/><category term="SQL interview"/><category term="Second Larges Number"/><category term="algorithms in java"/><category term="bubble sort"/><category term="insertion sort"/><category term="process management"/><category term="selection sort"/><category term="subquery"/><category term="system calls"/><title type='text'>Programming Hub</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>48</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-3648953258948041989</id><published>2021-04-17T11:58:00.005+05:30</published><updated>2021-04-17T12:06:34.914+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Array"/><category scheme="http://www.blogger.com/atom/ns#" term="JAVA"/><category scheme="http://www.blogger.com/atom/ns#" term="Second Larges Number"/><title type='text'>Java Program to find Second Largest Number in an Array</title><content type='html'>&lt;b style=&quot;background-color: #9fc5e8;&quot;&gt;Solution:&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;Before diving into the solution, let me tell you &lt;b style=&quot;background-color: #fff2cc;&quot;&gt;&lt;span style=&quot;color: #cc0000;&quot;&gt;this the most common question which gets asked in the most coding rounds&lt;/span&gt;&lt;/b&gt; and if you are being lazy to practice and learn this now, you are fooling yourself.&lt;br /&gt;Learn the logic behind this and you&#39;ll also realize after cracking the logic of this code you have learned a beautiful algorithm from DSA, but you have to figure out that yourself.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;public class SecondLargestInArrayExample{  &lt;br /&gt;public static int getSecondLargest(int[] a, int total){  &lt;br /&gt;int temp;  &lt;br /&gt;for (int i = 0; i &amp;lt; total; i++)   &lt;br /&gt;        &lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;{  &lt;br /&gt;            &lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;for (int j = i + 1; j &amp;lt; total; j++)   &lt;br /&gt;            &lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;{  &lt;br /&gt;                &lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;if (a[i] &amp;gt; a[j])   &lt;br /&gt;                &lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;{  &lt;br /&gt;                    &lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;/span&gt;temp = a[i];  &lt;br /&gt;                    &lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;a[i] = a[j];  &lt;br /&gt;                    &lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;a[j] = temp;  &lt;br /&gt;                &lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;}  &lt;br /&gt;            &lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/span&gt;}  &lt;br /&gt;        &lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;}  &lt;br /&gt;       return a[total-2];  &lt;br /&gt;}  &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;public static void main(String args[]){  &lt;br /&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;int a[]={1,2,5,6,3,2};  &lt;br /&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;int b[]={44,66,99,77,33,22,55};  &lt;br /&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;System.out.println(&quot;Second Largest: &quot;+getSecondLargest(a,6));  &lt;br /&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;System.out.println(&quot;Second Largest: &quot;+getSecondLargest(b,7));  &lt;br /&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;}  &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Output:&lt;span style=&quot;background-color: #fff2cc;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;pre style=&quot;font-size: 14px;&quot;&gt;Second Largest: 5
Second Largest: 77&lt;/pre&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/3648953258948041989/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2021/04/java-program-to-find-second-largest.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/3648953258948041989'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/3648953258948041989'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2021/04/java-program-to-find-second-largest.html' title='Java Program to find Second Largest Number in an Array'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-6627935437226622576</id><published>2021-04-17T11:29:00.002+05:30</published><updated>2021-04-17T11:29:17.104+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="subquery"/><category scheme="http://www.blogger.com/atom/ns#" term="TABLES"/><title type='text'>Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id.</title><content type='html'>&lt;p&gt;This one is little tricky problem. I tried to use subquery approach to solve this problem.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span style=&quot;background-color: #f7f9fa; color: #263238; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; font-size: 13px; white-space: pre-wrap;&quot;&gt;+----+------------------+&lt;/span&gt;&lt;/p&gt;&lt;pre style=&quot;background: rgb(247, 249, 250); border-radius: 3px; box-sizing: border-box; color: #263238; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; font-size: 13px; line-height: 1.6; margin-bottom: 1em; margin-top: 0px; overflow: auto; padding: 10px 15px; white-space: pre-wrap;&quot;&gt;| Id | Email            |
+----+------------------+
| 1  | john@example.com |
| 2  | bob@example.com  |
| 3  | john@example.com |
+----+------------------+
Id is the primary key column for this table.
&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #263238; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;; font-size: 14px; margin-bottom: 1em; margin-top: 0px;&quot;&gt;For example, after running your query, the above&amp;nbsp;&lt;code style=&quot;background-color: #f7f9fa; border-radius: 3px; box-sizing: border-box; color: #546e7a; font-size: 13px; padding: 2px 4px;&quot;&gt;Person&lt;/code&gt;&amp;nbsp;table should have the following rows:&lt;/p&gt;&lt;pre style=&quot;background: rgb(247, 249, 250); border-radius: 3px; box-sizing: border-box; color: #263238; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; font-size: 13px; line-height: 1.6; margin-bottom: 1em; margin-top: 0px; overflow: auto; padding: 10px 15px; white-space: pre-wrap;&quot;&gt;+----+------------------+
| Id | Email            |
+----+------------------+
| 1  | john@example.com |
| 2  | bob@example.com  |
+----+------------------+
&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #263238; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;; font-size: 14px; margin-bottom: 1em; margin-top: 0px;&quot;&gt;&lt;span style=&quot;box-sizing: border-box; font-weight: bolder;&quot;&gt;Note:&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;box-sizing: border-box; color: #263238; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;; font-size: 14px; margin-bottom: 1em; margin-top: 0px;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;Your output is the whole&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;background-color: #f7f9fa; border-radius: 3px; box-sizing: border-box; color: #546e7a; font-size: 13px; padding: 2px 4px;&quot;&gt;Person&lt;/code&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;table after executing your sql. Use&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;background-color: #f7f9fa; border-radius: 3px; box-sizing: border-box; color: #546e7a; font-size: 13px; padding: 2px 4px;&quot;&gt;delete&lt;/code&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;statement.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b style=&quot;background-color: #9fc5e8;&quot;&gt;Solution:&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;/p&gt;&lt;table class=&quot;highlight tab-size js-file-line-container&quot; data-paste-markdown-skip=&quot;&quot; data-tab-size=&quot;8&quot; style=&quot;background-color: white; border-collapse: collapse; border-spacing: 0px; color: #24292e; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Helvetica, Arial, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;; font-size: 14px; tab-size: 8;&quot;&gt;&lt;tbody style=&quot;box-sizing: border-box;&quot;&gt;&lt;tr style=&quot;box-sizing: border-box;&quot;&gt;&lt;td class=&quot;blob-code blob-code-inner js-file-line&quot; id=&quot;LC3&quot; style=&quot;box-sizing: border-box; color: var(--color-text-primary); font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);&quot;&gt;DELETE&lt;/span&gt; &lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);&quot;&gt;FROM&lt;/span&gt; Person &lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box;&quot;&gt;&lt;td class=&quot;blob-num js-line-number&quot; data-line-number=&quot;4&quot; id=&quot;L4&quot; style=&quot;box-sizing: border-box; color: var(--color-diff-blob-num-text); cursor: pointer; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50.4348px;&quot;&gt;&lt;/td&gt;&lt;td class=&quot;blob-code blob-code-inner js-file-line&quot; id=&quot;LC4&quot; style=&quot;box-sizing: border-box; color: var(--color-text-primary); font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);&quot;&gt;WHERE&lt;/span&gt; Id NOT &lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);&quot;&gt;IN&lt;/span&gt; (&lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;pl-c1&quot; style=&quot;box-sizing: border-box; color: var(--color-prettylights-syntax-constant);&quot;&gt;p&lt;/span&gt;.&lt;span class=&quot;pl-c1&quot; style=&quot;box-sizing: border-box; color: var(--color-prettylights-syntax-constant);&quot;&gt;id&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box;&quot;&gt;&lt;td class=&quot;blob-num js-line-number&quot; data-line-number=&quot;5&quot; id=&quot;L5&quot; style=&quot;box-sizing: border-box; color: var(--color-diff-blob-num-text); cursor: pointer; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50.4348px;&quot;&gt;&lt;/td&gt;&lt;td class=&quot;blob-code blob-code-inner js-file-line&quot; id=&quot;LC5&quot; style=&quot;box-sizing: border-box; color: var(--color-text-primary); font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;                 &lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);&quot;&gt;FROM&lt;/span&gt; (&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box;&quot;&gt;&lt;td class=&quot;blob-num js-line-number&quot; data-line-number=&quot;6&quot; id=&quot;L6&quot; style=&quot;box-sizing: border-box; color: var(--color-diff-blob-num-text); cursor: pointer; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50.4348px;&quot;&gt;&lt;/td&gt;&lt;td class=&quot;blob-code blob-code-inner js-file-line&quot; id=&quot;LC6&quot; style=&quot;box-sizing: border-box; color: var(--color-text-primary); font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;                       &lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);&quot;&gt;SELECT&lt;/span&gt; &lt;span class=&quot;pl-c1&quot; style=&quot;box-sizing: border-box; color: var(--color-prettylights-syntax-constant);&quot;&gt;MIN&lt;/span&gt;(Id) &lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);&quot;&gt;as&lt;/span&gt; id&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box;&quot;&gt;&lt;td class=&quot;blob-num js-line-number&quot; data-line-number=&quot;7&quot; id=&quot;L7&quot; style=&quot;box-sizing: border-box; color: var(--color-diff-blob-num-text); cursor: pointer; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50.4348px;&quot;&gt;&lt;/td&gt;&lt;td class=&quot;blob-code blob-code-inner js-file-line&quot; id=&quot;LC7&quot; style=&quot;box-sizing: border-box; color: var(--color-text-primary); font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;                       &lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);&quot;&gt;FROM&lt;/span&gt; Person&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box;&quot;&gt;&lt;td class=&quot;blob-num js-line-number&quot; data-line-number=&quot;8&quot; id=&quot;L8&quot; style=&quot;box-sizing: border-box; color: var(--color-diff-blob-num-text); cursor: pointer; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, monospace; font-size: 12px; line-height: 20px; min-width: 50px; padding: 0px 10px; text-align: right; user-select: none; vertical-align: top; white-space: nowrap; width: 50.4348px;&quot;&gt;&lt;/td&gt;&lt;td class=&quot;blob-code blob-code-inner js-file-line&quot; id=&quot;LC8&quot; style=&quot;box-sizing: border-box; color: var(--color-text-primary); font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, monospace; font-size: 12px; line-height: 20px; overflow-wrap: normal; overflow: visible; padding: 0px 10px; position: relative; vertical-align: top; white-space: pre;&quot;&gt;&lt;span style=&quot;background-color: #ffe599;&quot;&gt;                       &lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);&quot;&gt;GROUP BY&lt;/span&gt; Email) &lt;span class=&quot;pl-k&quot; style=&quot;box-sizing: border-box; color: var(--color-prettylights-syntax-keyword);&quot;&gt;as&lt;/span&gt; p);&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/6627935437226622576/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2021/04/write-sql-query-to-delete-all-duplicate.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/6627935437226622576'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/6627935437226622576'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2021/04/write-sql-query-to-delete-all-duplicate.html' title='Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-8505382398935363415</id><published>2021-04-17T11:09:00.009+05:30</published><updated>2021-04-17T11:10:46.370+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="JOINS"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL interview"/><category scheme="http://www.blogger.com/atom/ns#" term="TABLES"/><title type='text'>Combine Tables. [Leetcode Problem]</title><content type='html'>&lt;p&gt;&amp;nbsp; 1. Combine Tables. [Leetcode problem]&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;T&lt;span style=&quot;background-color: white; color: #263238; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;; font-size: 14px;&quot;&gt;able:&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #263238; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;; font-size: 14px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;code style=&quot;background-color: #f7f9fa; border-radius: 3px; box-sizing: border-box; color: #546e7a; font-size: 13px; padding: 2px 4px;&quot;&gt;Person&lt;/code&gt;&lt;/p&gt;&lt;pre style=&quot;background: rgb(247, 249, 250); border-radius: 3px; box-sizing: border-box; color: #263238; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; font-size: 13px; line-height: 1.6; margin-bottom: 1em; margin-top: 0px; overflow: auto; padding: 10px 15px; white-space: pre-wrap;&quot;&gt;+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| PersonId    | int     |
| FirstName   | varchar |
| LastName    | varchar |
+-------------+---------+
PersonId is the primary key column for this table.
&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #263238; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;; font-size: 14px; margin-bottom: 1em; margin-top: 0px;&quot;&gt;Table:&amp;nbsp;&lt;code style=&quot;background-color: #f7f9fa; border-radius: 3px; box-sizing: border-box; color: #546e7a; font-size: 13px; padding: 2px 4px;&quot;&gt;Address&lt;/code&gt;&lt;/p&gt;&lt;pre style=&quot;background: rgb(247, 249, 250); border-radius: 3px; box-sizing: border-box; color: #263238; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; font-size: 13px; line-height: 1.6; margin-bottom: 1em; margin-top: 0px; overflow: auto; padding: 10px 15px; white-space: pre-wrap;&quot;&gt;+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| AddressId   | int     |
| PersonId    | int     |
| City        | varchar |
| State       | varchar |
+-------------+---------+
AddressId is the primary key column for this table.
&lt;/pre&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #263238; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;; font-size: 14px; margin-bottom: 1em; margin-top: 0px;&quot;&gt;&amp;nbsp;&lt;/p&gt;&lt;p style=&quot;background-color: white; box-sizing: border-box; color: #263238; font-family: -apple-system, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;Helvetica Neue&amp;quot;, Helvetica, Arial, sans-serif, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;; font-size: 14px; margin-bottom: 1em; margin-top: 0px;&quot;&gt;Write a SQL query for a report that provides the following information for each person in the Person table, regardless if there is an address for each of those people:&lt;/p&gt;&lt;pre style=&quot;background: rgb(247, 249, 250); border-radius: 3px; box-sizing: border-box; color: #263238; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; font-size: 13px; line-height: 1.6; margin-bottom: 1em; margin-top: 0px; overflow: auto; padding: 10px 15px; white-space: pre-wrap;&quot;&gt;FirstName, LastName, City, State
&lt;/pre&gt;&lt;blockquote&gt;&lt;pre style=&quot;background: rgb(247, 249, 250); border-radius: 3px; box-sizing: border-box; color: #263238; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; font-size: 13px; line-height: 1.6; margin-bottom: 1em; margin-top: 0px; overflow: auto; padding: 10px 15px; white-space: pre-wrap;&quot;&gt;Ref: https://leetcode.com/problems/combine-two-tables/&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;span style=&quot;background-color: #76a5af;&quot;&gt;&lt;b&gt;&lt;span style=&quot;font-family: trebuchet;&quot;&gt;&amp;nbsp;Solution:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #263238; font-family: SFMono-Regular, Consolas, &amp;quot;Liberation Mono&amp;quot;, Menlo, Courier, monospace; font-size: 13px; white-space: pre-wrap;&quot;&gt;
&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white; color: rgba(0, 0, 0, 0.9); font-family: -apple-system, system-ui, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;Fira Sans&amp;quot;, Ubuntu, Oxygen, &amp;quot;Oxygen Sans&amp;quot;, Cantarell, &amp;quot;Droid Sans&amp;quot;, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;, &amp;quot;Lucida Grande&amp;quot;, Helvetica, Arial, sans-serif; font-size: 14px;&quot;&gt;A common mistake would be to use INNER JOIN and not LEFT (or RIGHT) JOIN and ending up omitting records with no addresses but as it is asked to include those records as well, we will need to use LEFT (or RIGHT) JOIN.&lt;/span&gt;&lt;/p&gt;&lt;span style=&quot;background-color: white; color: rgba(0, 0, 0, 0.9); font-family: -apple-system, system-ui, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;Fira Sans&amp;quot;, Ubuntu, Oxygen, &amp;quot;Oxygen Sans&amp;quot;, Cantarell, &amp;quot;Droid Sans&amp;quot;, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;, &amp;quot;Lucida Grande&amp;quot;, Helvetica, Arial, sans-serif; font-size: 14px;&quot;&gt;Also, since these selected columns are unique among both the tables, I omitted the table prefix from all the columns in SELECT clause.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Query:&amp;nbsp;&lt;/span&gt;&lt;div&gt;&lt;span style=&quot;background-color: #ffe599; color: rgba(0, 0, 0, 0.9); font-family: -apple-system, system-ui, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;Fira Sans&amp;quot;, Ubuntu, Oxygen, &amp;quot;Oxygen Sans&amp;quot;, Cantarell, &amp;quot;Droid Sans&amp;quot;, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;, &amp;quot;Lucida Grande&amp;quot;, Helvetica, Arial, sans-serif; font-size: 14px;&quot;&gt;Select Firstname, LastName, City, State&amp;nbsp;&lt;/span&gt;&lt;div&gt;&lt;span style=&quot;color: rgba(0, 0, 0, 0.901960784313726); font-family: -apple-system, system-ui, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica Neue, Fira Sans, Ubuntu, Oxygen, Oxygen Sans, Cantarell, Droid Sans, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Lucida Grande, Helvetica, Arial, sans-serif;&quot;&gt;&lt;span style=&quot;background-color: #ffe599; font-size: 14px;&quot;&gt;FROM Person p&lt;br /&gt;&amp;nbsp; &amp;nbsp;LEFT JOIN address a&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #ffe599; color: rgba(0, 0, 0, 0.9); font-family: -apple-system, system-ui, BlinkMacSystemFont, &amp;quot;Segoe UI&amp;quot;, Roboto, &amp;quot;Helvetica Neue&amp;quot;, &amp;quot;Fira Sans&amp;quot;, Ubuntu, Oxygen, &amp;quot;Oxygen Sans&amp;quot;, Cantarell, &amp;quot;Droid Sans&amp;quot;, &amp;quot;Apple Color Emoji&amp;quot;, &amp;quot;Segoe UI Emoji&amp;quot;, &amp;quot;Segoe UI Symbol&amp;quot;, &amp;quot;Lucida Grande&amp;quot;, Helvetica, Arial, sans-serif; font-size: 14px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ON p.PersonId = a.PersonId;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/8505382398935363415/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2021/04/combine-tables-leetcode-problem.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/8505382398935363415'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/8505382398935363415'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2021/04/combine-tables-leetcode-problem.html' title='Combine Tables. [Leetcode Problem]'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-2075032907600576299</id><published>2020-11-18T12:23:00.002+05:30</published><updated>2021-01-23T13:17:55.124+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="process management"/><category scheme="http://www.blogger.com/atom/ns#" term="SPOS lab"/><category scheme="http://www.blogger.com/atom/ns#" term="system calls"/><title type='text'>Implement UNIX system calls like ps, fork, join, exec family, and wait for process management (use shell script/ Java/ C programming). </title><content type='html'>&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;//A small example to show how to use execvp() function in C. We will have&lt;/p&gt;&lt;p&gt;two .C files , EXEC.c and execDemo.c and we will replace the execDemo.c with EXEC.c by&lt;/p&gt;&lt;p&gt;calling execvp() function in execDemo.c .&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;//EXEC.c&amp;nbsp;&lt;/p&gt;&lt;p&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;#include&amp;lt;unistd.h&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;int main()&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;{&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; int i;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;This&amp;nbsp; is EXEC.c, called by execvp() &quot;);&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; printf(&quot;\n&quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; return 0;&lt;/p&gt;&lt;p&gt;&amp;nbsp; }&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Now,create an executable file of EXEC.c using command&lt;/p&gt;&lt;p&gt;&amp;nbsp;gcc EXEC.c -o EXEC&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;//execDemo.c&lt;/p&gt;&lt;p&gt;#include&amp;lt;stdio.h&amp;gt;&lt;/p&gt;&lt;p&gt;#include&amp;lt;stdlib.h&amp;gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;#include&amp;lt;unistd.h&amp;gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;int main()&lt;/p&gt;&lt;p&gt;&amp;nbsp;{&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; //A null terminated array of character&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; //pointers&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;char *args[]={&quot;./EXEC&quot;,NULL};&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;execvp(args[0],args);&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; /*All statements are ignored after execvp() call as this whole process(execDemo.c) is replaced by&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;another process (EXEC.c) */&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;printf(&quot;Ending-----&quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;return 0;&amp;nbsp;&lt;/p&gt;&lt;p&gt;}&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Now, create an executable file of execDemo.c using command gcc execDemo.c -o execDemo&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;After running the executable file of execDemo.cby using command ./excDemo, we get the following output:&amp;nbsp;&lt;/p&gt;&lt;p&gt;This is EXEC.c, called by execvp()&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;When the file execDemo.c is compiled, as soon as the statement execvp(args[0],args) is&lt;/p&gt;&lt;p&gt;executed, this very program is replaced by the program EXEC.c. is not printed because&lt;/p&gt;&lt;p&gt;because as soon as the execvp() function is called, this program is replaced by the&lt;/p&gt;&lt;p&gt;program EXEC.c.&lt;/p&gt;&lt;p&gt;execv : This is very similar to execvp() function in terms of syntax as well. The syntax of&lt;/p&gt;&lt;p&gt;execv() is as shown below:Syntax:&lt;/p&gt;&lt;p&gt;int execv(const char *path, char *const argv[]);&lt;/p&gt;&lt;p&gt;path: should point to the path of the file being executed.&lt;/p&gt;&lt;p&gt;argv[]: is a null terminated array of character pointers.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/2075032907600576299/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2020/11/implement-unix-system-calls-like-ps.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/2075032907600576299'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/2075032907600576299'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2020/11/implement-unix-system-calls-like-ps.html' title='Implement UNIX system calls like ps, fork, join, exec family, and wait for process management (use shell script/ Java/ C programming). '/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-5341825492207034997</id><published>2020-11-18T12:14:00.005+05:30</published><updated>2021-02-07T12:19:42.930+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="macro processor"/><category scheme="http://www.blogger.com/atom/ns#" term="SPOS"/><title type='text'>Write a Java program for pass-II of a two-pass macro-processor. The output of assignment-3 (MNT, MDT and file without any macro definitions) should be input for this assignment.</title><content type='html'>&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;pre class=&quot;ndfHFb-c4YZDc-fmcmS-DARUcf&quot; style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace, arial, sans-serif; font-size: 14px; margin-bottom: 0px; margin-top: 0px; overflow-wrap: break-word; user-select: text; white-space: pre-wrap;&quot;&gt;import java.io.*;
import java.util.HashMap;
import java.util.Vector;

public class macroPass2 {
	public static void main(String[] Args) throws IOException{
		BufferedReader b1 = new BufferedReader(new FileReader(&quot;intermediate.txt&quot;));
		BufferedReader b2 = new BufferedReader(new FileReader(&quot;mnt.txt&quot;));
		BufferedReader b3 = new BufferedReader(new FileReader(&quot;mdt.txt&quot;));
		BufferedReader b4 = new BufferedReader(new FileReader(&quot;kpdt.txt&quot;));
		FileWriter f1 = new FileWriter(&quot;Pass2.txt&quot;);
		HashMap&amp;lt;Integer,String&amp;gt; aptab=new HashMap&amp;lt;Integer,String&amp;gt;();
		HashMap&amp;lt;String,Integer&amp;gt; aptabInverse=new HashMap&amp;lt;String,Integer&amp;gt;();
		HashMap&amp;lt;String,Integer&amp;gt; mdtpHash=new HashMap&amp;lt;String,Integer&amp;gt;();
		HashMap&amp;lt;String,Integer&amp;gt; kpdtpHash=new HashMap&amp;lt;String,Integer&amp;gt;();
		HashMap&amp;lt;String,Integer&amp;gt; kpHash=new HashMap&amp;lt;String,Integer&amp;gt;();
		HashMap&amp;lt;String,Integer&amp;gt; macroNameHash=new HashMap&amp;lt;String,Integer&amp;gt;();
		Vector&amp;lt;String&amp;gt;mdt=new Vector&amp;lt;String&amp;gt;();
		Vector&amp;lt;String&amp;gt;kpdt=new Vector&amp;lt;String&amp;gt;();
		String s,s1;
		int i,pp,kp,kpdtp,mdtp,paramNo;
		while((s=b3.readLine())!=null)
			mdt.addElement(s);
		while((s=b4.readLine())!=null)
			kpdt.addElement(s);
		while((s=b2.readLine())!=null){
			String word[]=s.split(&quot;\t&quot;);
			s1=word[0]+word[1];
			macroNameHash.put(word[0],1);
			kpHash.put(s1,Integer.parseInt(word[2]));
			mdtpHash.put(s1,Integer.parseInt(word[3]));
			kpdtpHash.put(s1,Integer.parseInt(word[4]));
		}
		while((s=b1.readLine())!=null){
			String b1Split[]=s.split(&quot;\\s&quot;);
			if(macroNameHash.containsKey(b1Split[0])){
				pp= b1Split[1].split(&quot;,&quot;).length-b1Split[1].split(&quot;=&quot;).length+1;
				kp=kpHash.get(b1Split[0]+Integer.toString(pp));
				mdtp=mdtpHash.get(b1Split[0]+Integer.toString(pp));
				kpdtp=kpdtpHash.get(b1Split[0]+Integer.toString(pp));
				String actualParams[]=b1Split[1].split(&quot;,&quot;);
				paramNo=1;
				for(int j=0;j&amp;lt;pp;j++){
					aptab.put(paramNo, actualParams[paramNo-1]);
					aptabInverse.put(actualParams[paramNo-1],paramNo);
					paramNo++;
				}
				i=kpdtp-1;
				for(int j=0;j&amp;lt;kp;j++){
					String temp[]=kpdt.get(i).split(&quot;\t&quot;);
					aptab.put(paramNo,temp[1]);
					aptabInverse.put(temp[0],paramNo);
					i++;
					paramNo++;
				}
				i=pp+1;
				while(i&amp;lt;=actualParams.length){
					String initializedParams[]=actualParams[i-1].split(&quot;=&quot;);
					aptab.put(aptabInverse.get(initializedParams[0].substring(1,initializedParams[0].length())),initializedParams[1].substring(0,initializedParams[1].length()));
					i++;
				}
				i=mdtp-1;
				while(mdt.get(i).compareToIgnoreCase(&quot;MEND&quot;)!=0){
					f1.write(&quot;+ &quot;);
					for(int j=0;j&amp;lt;mdt.get(i).length();j++){
						if(mdt.get(i).charAt(j)==&#39;#&#39;)
							f1.write(aptab.get(Integer.parseInt(&quot;&quot; + mdt.get(i).charAt(++j))));
						else
							f1.write(mdt.get(i).charAt(j));
					}
					f1.write(&quot;\n&quot;);
					i++;
				}
				aptab.clear();
				aptabInverse.clear();
			}
			else
				f1.write(&quot;+ &quot;+s+&quot;\n&quot;);
		}
		b1.close();
		b2.close();
		b3.close();
		b4.close();
		f1.close();
	}
}

/*
OUTPUT:
&lt;span style=&quot;color: #212121;&quot;&gt;XXXXXXXXX&lt;/span&gt;:~/Desktop/XXXXXXXXX/A4$ javac macroPass2.java &lt;br /&gt;&lt;span style=&quot;color: #212121;&quot;&gt;XXXXXXXXX&lt;/span&gt;:~/Desktop/XXXXXXXXX/A4$ java macroPass2 &lt;br /&gt;&lt;span style=&quot;color: #212121;&quot;&gt;XXXXXXXXX&lt;/span&gt;:~/Desktop/XXXXXXXXX/A4$ cat Pass2.txt &lt;br /&gt;+ MOVE AREG,10
+ ADD AREG,=&#39;1&#39;
+ MOVER AREG,20
+ ADD AREG,=&#39;5&#39;
+ MOVER &amp;amp;AREG,100
+ MOVER &amp;amp;BREG,200
+ ADD &amp;amp;AREG,=&#39;15&#39;
+ ADD &amp;amp;BREG,=&#39;10&#39;
&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/5341825492207034997/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2020/11/implement-pass-II-of-a-two-pass-macro-processor.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/5341825492207034997'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/5341825492207034997'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2020/11/implement-pass-II-of-a-two-pass-macro-processor.html' title='Write a Java program for pass-II of a two-pass macro-processor. The output of assignment-3 (MNT, MDT and file without any macro definitions) should be input for this assignment.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-7582866088940082028</id><published>2020-11-17T12:04:00.011+05:30</published><updated>2021-02-07T12:16:58.953+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="macro processor"/><category scheme="http://www.blogger.com/atom/ns#" term="SPOS"/><title type='text'>Design suitable data structures and implement pass-I of a two-pass macro-processor using OOP features in Java.</title><content type='html'>&lt;p&gt;&amp;nbsp;&lt;span face=&quot;&amp;quot;Courier New&amp;quot;, Courier, monospace, arial, sans-serif&quot; style=&quot;background-color: white; font-size: 14px; white-space: pre-wrap;&quot;&gt;/*&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;ndfHFb-c4YZDc-fmcmS-DARUcf&quot; style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace, arial, sans-serif; font-size: 14px; margin-bottom: 0px; margin-top: 0px; overflow-wrap: break-word; user-select: text; white-space: pre-wrap;&quot;&gt;Problem Statement: Design suitable data structures and implement pass-I of a two-pass macro-processor using
OOP features in Java
*/
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;

public class macroPass1 {
	public static void main(String[] Args) throws IOException{
		BufferedReader b1 = new BufferedReader(new FileReader(&quot;input.txt&quot;));
		FileWriter f1 = new FileWriter(&quot;intermediate.txt&quot;);
		FileWriter f2 = new FileWriter(&quot;mnt.txt&quot;);
		FileWriter f3 = new FileWriter(&quot;mdt.txt&quot;);
		FileWriter f4 = new FileWriter(&quot;kpdt.txt&quot;);
		HashMap&amp;lt;String,Integer&amp;gt; pntab=new HashMap&amp;lt;String,Integer&amp;gt;();
		String s;
		int paramNo=1,mdtp=1,flag=0,pp=0,kp=0,kpdtp=0;
		while((s=b1.readLine())!=null){
			String word[]=s.split(&quot;\\s&quot;);		//separate by space
			if(word[0].compareToIgnoreCase(&quot;MACRO&quot;)==0){
				flag=1;
				if(word.length&amp;lt;=2){
					f2.write(word[1]+&quot;\t&quot;+pp+&quot;\t&quot;+kp+&quot;\t&quot;+mdtp+&quot;\t&quot;+(kp==0?kpdtp:(kpdtp+1))+&quot;\n&quot;);
					continue;
				}
				String params[]=word[2].split(&quot;,&quot;);
				for(int i=0;i&amp;lt;params.length;i++){
					if(params[i].contains(&quot;=&quot;)){
						kp++;
						String keywordParam[]=params[i].split(&quot;=&quot;);
						pntab.put(keywordParam[0].substring(1,keywordParam[0].length()),paramNo++);
						if(keywordParam.length==2)
							f4.write(keywordParam[0].substring(1,keywordParam[0].length())+&quot;\t&quot;+keywordParam[1]+&quot;\n&quot;);
						else
							f4.write(keywordParam[0].substring(1,keywordParam[0].length())+&quot;\t&quot;+&quot;-&quot;+&quot;\n&quot;);
							
					}
					else{
						pntab.put(params[i].substring(1,params[i].length()),paramNo++);
						pp++;
					}
				}
				f2.write(word[1]+&quot;\t&quot;+pp+&quot;\t&quot;+kp+&quot;\t&quot;+mdtp+&quot;\t&quot;+(kp==0?kpdtp:(kpdtp+1))+&quot;\n&quot;);
				kpdtp+=kp;
			}
			else if(word[0].compareToIgnoreCase(&quot;MEND&quot;)==0){
				f3.write(s+&#39;\n&#39;);
				flag=pp=kp=0;
				mdtp++;
				paramNo=1;
				pntab.clear();
			}
			else if(flag==1){
				for(int i=0;i&amp;lt;s.length();i++){
					if(s.charAt(i)==&#39;&amp;amp;&#39;){
						i++;
						String temp=&quot;&quot;;
						while(!(s.charAt(i)==&#39; &#39;||s.charAt(i)==&#39;,&#39;)){
							temp+=s.charAt(i++);
							if(i==s.length())
								break;
							
						}
						i--;
						f3.write(&quot;#&quot;+pntab.get(temp));
					}
					else
						f3.write(s.charAt(i));
				}
				f3.write(&quot;\n&quot;);
				mdtp++;
			}
			else{
				f1.write(s+&#39;\n&#39;);
			}
		}
		b1.close();
		f1.close();
		f2.close();
		f3.close();
		f4.close();
	}
}
/*
OUTPUT:

XXXXXXXXX:~/Desktop/XXXXXXXXX/A3$ javac macroPass1.java &lt;/pre&gt;&lt;pre class=&quot;ndfHFb-c4YZDc-fmcmS-DARUcf&quot; style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace, arial, sans-serif; font-size: 14px; margin-bottom: 0px; margin-top: 0px; overflow-wrap: break-word; user-select: text; white-space: pre-wrap;&quot;&gt;XXXXXXXXX:~/Desktop/XXXXXXXXX/A3$ java macroPass1 &lt;br /&gt;
XXXXXXXXX:~/Desktop/XXXXXXXXX/A3$ cat intermediate.txt &lt;br /&gt;M1 10,20,&amp;amp;b=CREG
M2 100,200,&amp;amp;u=AREG,&amp;amp;v=BREG

XXXXXXXXX:~/A3$ cat mnt.txt 
M1	2	2	1	1
M2	2	2	7	3
M3	2	0	13	4

XXXXXXXXX:~/Desktop/XXXXXXXXX/A3$ cat mdt.txt &lt;br /&gt;MOVE #3,#1
ADD #3,=&#39;1&#39;
MOVER #3,#2
M2 69,169
ADD #3,=&#39;5&#39;
MEND
MOVER #3,#1
MOVER #4,#2
M3 73,173
ADD #3,=&#39;15&#39;
ADD #4,=&#39;10&#39;
MEND
ADD #1,#2
MEND

XXXXXXXXX:~/Desktop/XXXXXXXXX/A3$ cat kpdt.txt &lt;br /&gt;a	AREG
b	-
u	CREG
v	DREG

*/&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/7582866088940082028/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2020/11/implement-pass-I-of-a-two-pass-macro-processor.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/7582866088940082028'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/7582866088940082028'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2020/11/implement-pass-I-of-a-two-pass-macro-processor.html' title='Design suitable data structures and implement pass-I of a two-pass macro-processor using OOP features in Java.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-7559392902656163240</id><published>2020-11-15T13:27:00.002+05:30</published><updated>2020-11-15T13:28:39.196+05:30</updated><title type='text'>Abstract class and method in Java.</title><content type='html'>&lt;div style=&quot;text-align: left;&quot;&gt;&lt;b style=&quot;background-color: #d5a6bd;&quot;&gt;Abstract Class:&lt;/b&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; An &lt;b&gt;abstract class&lt;/b&gt; is something which is incomplete and you can not create an instance of the abstract class. If you want to use it you need to make it complete or concrete by extending it. It is created using &lt;b&gt;abstract &lt;/b&gt;keyword. This class can contain abstract and non abstract methods. Before learning about abstract class and abstract I recommend you to first learn about &lt;a href=&quot;https://meetshrikantb.blogspot.com/2020/11/abstraction-vs-encapsulation.html&quot; style=&quot;background-color: #d5a6bd;&quot; target=&quot;_blank&quot;&gt;abstraction&lt;/a&gt; concept in Java.&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Few important things to remember about abstract class:&lt;/h3&gt;&lt;h4 style=&quot;text-align: left;&quot;&gt;&lt;ul class=&quot;points&quot; style=&quot;background-color: white; font-size: 13px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; list-style: circle;&quot;&gt;&lt;li style=&quot;line-height: 21px; margin-top: 4px; padding: 0.2em;&quot;&gt;&lt;span style=&quot;color: #45818e; font-family: georgia;&quot;&gt;An abstract class must be declared with an abstract keyword.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;ul class=&quot;points&quot; style=&quot;background-color: white; font-size: 13px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; list-style: circle;&quot;&gt;&lt;li style=&quot;line-height: 21px; margin-top: 4px; padding: 0.2em;&quot;&gt;&lt;span style=&quot;color: #45818e; font-family: georgia;&quot;&gt;It can have abstract and non-abstract methods.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;ul class=&quot;points&quot; style=&quot;background-color: white; font-size: 13px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; list-style: circle;&quot;&gt;&lt;li style=&quot;line-height: 21px; margin-top: 4px; padding: 0.2em;&quot;&gt;&lt;span style=&quot;color: #45818e; font-family: georgia;&quot;&gt;It cannot be instantiated.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;ul class=&quot;points&quot; style=&quot;background-color: white; font-size: 13px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; list-style: circle;&quot;&gt;&lt;li style=&quot;line-height: 21px; margin-top: 4px; padding: 0.2em;&quot;&gt;&lt;span style=&quot;color: #45818e; font-family: georgia;&quot;&gt;It can have&amp;nbsp;constructors&amp;nbsp;and static methods also.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;ul class=&quot;points&quot; style=&quot;background-color: white; font-size: 13px; font-stretch: normal; font-variant-east-asian: normal; font-variant-numeric: normal; line-height: normal; list-style: circle;&quot;&gt;&lt;li style=&quot;line-height: 21px; margin-top: 4px; padding: 0.2em;&quot;&gt;&lt;span style=&quot;color: #45818e; font-family: georgia;&quot;&gt;It can have final methods which will force the subclass not to change the body of the method.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;span style=&quot;color: #45818e; font-family: georgia;&quot;&gt;&lt;span style=&quot;font-size: 13px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;p style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;font-family: georgia;&quot;&gt;&lt;span style=&quot;font-weight: 400;&quot;&gt;Example of Abstract class with abstract method:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #d0e0e3;&quot;&gt;&lt;span class=&quot;keyword&quot; style=&quot;border: none; color: #006699; font-family: verdana; font-size: 13px; margin: 0px; padding: 0px;&quot;&gt;abstract&lt;/span&gt;&lt;span style=&quot;border: none; font-family: verdana; font-size: 13px; font-weight: 400; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot; style=&quot;border: none; color: #006699; font-family: verdana; font-size: 13px; margin: 0px; padding: 0px;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;border: none; font-family: verdana; font-size: 13px; font-weight: 400; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;Animal{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: verdana; font-size: 13px; font-weight: 400;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot; style=&quot;border: none; color: #006699; font-family: verdana; font-size: 13px; margin: 0px; padding: 0px;&quot;&gt;abstract&lt;/span&gt;&lt;span style=&quot;border: none; font-family: verdana; font-size: 13px; font-weight: 400; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot; style=&quot;border: none; color: #006699; font-family: verdana; font-size: 13px; margin: 0px; padding: 0px;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;border: none; font-family: verdana; font-size: 13px; font-weight: 400; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;run();&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: verdana; font-size: 13px; font-weight: 400;&quot;&gt;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword&quot; style=&quot;border: none; color: #006699; font-family: verdana; font-size: 13px; margin: 0px; padding: 0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #d0e0e3;&quot;&gt;&lt;span class=&quot;keyword&quot; style=&quot;border: none; color: #006699; font-family: verdana; font-size: 13px; margin: 0px; padding: 0px;&quot;&gt;class&lt;/span&gt;&lt;span style=&quot;border: none; font-family: verdana; font-size: 13px; font-weight: 400; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;Horse&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot; style=&quot;border: none; color: #006699; font-family: verdana; font-size: 13px; margin: 0px; padding: 0px;&quot;&gt;extends&lt;/span&gt;&lt;span style=&quot;border: none; font-family: verdana; font-size: 13px; font-weight: 400; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;Animal{&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword&quot; style=&quot;border: none; color: #006699; font-family: verdana; font-size: 13px; margin: 0px; padding: 0px;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;border: none; font-family: verdana; font-size: 13px; font-weight: 400; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;run()&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #d0e0e3; border: none; font-family: verdana; font-size: 13px; font-weight: 400; margin: 0px; padding: 0px;&quot;&gt;{&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #d0e0e3;&quot;&gt;&lt;span style=&quot;border: none; font-family: verdana; font-size: 13px; font-weight: 400; margin: 0px; padding: 0px;&quot;&gt;&lt;span&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;/span&gt;System.out.println(&lt;/span&gt;&lt;span class=&quot;string&quot; style=&quot;border: none; color: blue; font-family: verdana; font-size: 13px; font-weight: 400; margin: 0px; padding: 0px;&quot;&gt;&quot;Runs fast&quot;&lt;/span&gt;&lt;span style=&quot;border: none; font-family: verdana; font-size: 13px; font-weight: 400; margin: 0px; padding: 0px;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #d0e0e3;&quot;&gt;&lt;span style=&quot;border: none; font-family: verdana; font-size: 13px; font-weight: 400; margin: 0px; padding: 0px;&quot;&gt;}&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;keyword&quot; style=&quot;border: none; color: #006699; font-family: verdana; font-size: 13px; margin: 0px; padding: 0px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #d0e0e3;&quot;&gt;&lt;span class=&quot;keyword&quot; style=&quot;border: none; color: #006699; font-family: verdana; font-size: 13px; margin: 0px; padding: 0px;&quot;&gt;public&lt;/span&gt;&lt;span style=&quot;border: none; font-family: verdana; font-size: 13px; font-weight: 400; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot; style=&quot;border: none; color: #006699; font-family: verdana; font-size: 13px; margin: 0px; padding: 0px;&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;border: none; font-family: verdana; font-size: 13px; font-weight: 400; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot; style=&quot;border: none; color: #006699; font-family: verdana; font-size: 13px; margin: 0px; padding: 0px;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;border: none; font-family: verdana; font-size: 13px; font-weight: 400; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;main(String&amp;nbsp;args[]){&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: verdana; font-size: 13px; font-weight: 400;&quot;&gt;Animal obj&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;keyword&quot; style=&quot;border: none; color: #006699; font-family: verdana; font-size: 13px; margin: 0px; padding: 0px;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;border: none; font-family: verdana; font-size: 13px; font-weight: 400; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;Horse();&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: verdana; font-size: 13px; font-weight: 400;&quot;&gt;&amp;nbsp;obj.run();&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: verdana; font-size: 13px; font-weight: 400;&quot;&gt;}&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #d0e0e3; font-family: verdana; font-size: 13px; font-weight: 400;&quot;&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #d0e0e3; font-family: verdana; font-size: 13px; font-weight: 400;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #d0e0e3; font-family: verdana; font-size: 13px; font-weight: 400;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;span style=&quot;background-color: #d5a6bd; font-family: verdana; font-size: 13px;&quot;&gt;Abstract Method:&lt;/span&gt;&lt;/div&gt;&lt;/h4&gt;&lt;p&gt;&lt;span style=&quot;background-color: #f3f3f3;&quot;&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/b&gt;A method can also be declared as abstract, it does not have any implementation details.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;background-color: #f3f3f3;&quot;&gt;Example:&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #0b5394;&quot;&gt;&lt;b&gt;abstract&lt;/b&gt; &lt;/span&gt;&lt;span style=&quot;background-color: #cfe2f3;&quot;&gt;void demoAbstract();//empty body, use abstract keyword&lt;/span&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;color: #e06666;&quot;&gt;*Above program is example of abstract class with abstract method.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;p&gt;&lt;b style=&quot;background-color: #d5a6bd;&quot;&gt;Note: By the way, Java has concept of abstract classes and abstract methods but a variable in Java can not be abstract.&lt;/b&gt;&lt;/p&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/7559392902656163240/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2020/11/abstract-class-and-method-in-java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/7559392902656163240'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/7559392902656163240'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2020/11/abstract-class-and-method-in-java.html' title='Abstract class and method in Java.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-1627703169736102917</id><published>2020-11-15T12:16:00.001+05:30</published><updated>2020-11-15T12:16:35.726+05:30</updated><title type='text'>Abstraction vs Encapsulation.</title><content type='html'>&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;An OOP concept which &lt;u&gt;&lt;b&gt;focuses on relevant information by hiding unnecessary details&lt;/b&gt;.&lt;/u&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Abstraction hides complexity by giving more abstract picture, sort of 10000 feet view while &lt;u&gt;Encapsulation &lt;b&gt;hides internal working &lt;/b&gt;so that you can change it later.&amp;nbsp;&lt;/u&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: #134f5c;&quot;&gt;&lt;b&gt;Abstraction hides details at design level, while encapsulation hides details at implementation level.&lt;/b&gt; &lt;/span&gt;Its sole purpose is to hide the internal working of objects from the outside world so that you can change it later without impacting outside clients.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/b&gt;Abstraction is about hiding unwanted details while giving out the most essential details, while encapsulation means hiding the code and data into a single unit e.g. class or method to protect the inner working of an object from the outside world.&lt;/p&gt;&lt;p&gt;(Abstraction can also be thought of as extracting common details or generalizing things).&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Abstraction lets you focus on what object does instead of how it does, while encapsulation means hiding the internal details of how an object works.&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; In java, &lt;span style=&quot;color: #134f5c;&quot;&gt;&lt;b&gt;abstraction is supported&lt;/b&gt; using &lt;b&gt;interface&lt;/b&gt; &lt;/span&gt;&lt;b&gt;&lt;span style=&quot;color: #134f5c;&quot;&gt;and abstract class&lt;/span&gt;&amp;nbsp;&lt;/b&gt;&amp;nbsp;while &lt;span style=&quot;color: #134f5c;&quot;&gt;&lt;b&gt;encapsulation is supported&lt;/b&gt; using &lt;b&gt;access modifiers &lt;/b&gt;&lt;/span&gt;e.g. public, private and protected.&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;One example of abstraction is creating an interface to denote common behaviour without specifying any details about how that behaviour works like you create an interface called &lt;b&gt;Server &lt;/b&gt;which has the start() and stop() method. This is called abstraction of &lt;b&gt;Server&amp;nbsp; &lt;/b&gt;because every server should have a way to start and stop and details may differ from each other.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/1627703169736102917/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2020/11/abstraction-vs-encapsulation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/1627703169736102917'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/1627703169736102917'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2020/11/abstraction-vs-encapsulation.html' title='Abstraction vs Encapsulation.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-4002222278982248873</id><published>2020-11-06T14:15:00.004+05:30</published><updated>2020-11-06T14:15:57.694+05:30</updated><title type='text'>Difference between Class and Object.</title><content type='html'>&lt;p&gt;Class is a blue print or a model, objects are actual things which are created using these blue prints/models.&lt;/p&gt;&lt;p&gt;Generally, objects are created at runtime when you start JVM with&amp;nbsp;&lt;b&gt;java&amp;nbsp;&lt;/b&gt;command and JVM will start executing your code, whenever JVM encounters&amp;nbsp;&lt;b&gt;new&amp;nbsp;&lt;/b&gt;keyword it will create an object.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/4002222278982248873/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2020/11/difference-between-class-and-object.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/4002222278982248873'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/4002222278982248873'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2020/11/difference-between-class-and-object.html' title='Difference between Class and Object.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-8578422780768054429</id><published>2020-11-04T10:50:00.003+05:30</published><updated>2020-11-04T10:50:43.709+05:30</updated><title type='text'>What are Objects in Object Oriented Programming aka OOP?</title><content type='html'>&lt;p&gt;This could be best way to answer what are Objects in Java, this is more than enough for a beginner level engineer, keep note of following information&lt;/p&gt;&lt;p&gt;Objects are instances of class, class defines blue prints and objects are things which are created based upon that blueprint.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Object is also known as instance in Java, e.g. when we say an instance of String class, we actually mean an object of String class.&lt;/p&gt;&lt;p&gt;Object has state and behaviour.&lt;/p&gt;&lt;p&gt;State: State is represented using instance variable and static variable.&lt;/p&gt;&lt;p&gt;Behaviour: And behaviours are implemented using methods in Java.&lt;/p&gt;&lt;p&gt;The things which differentiate two objects of same class are their states e.g. if we take two instances of String class &#39;A&#39; &amp;amp; &#39;B&#39; their contents are different which is nothing but their state.&lt;/p&gt;&lt;p&gt;There are several ways to create objects in Java, .e.g., Serialization. Cloning, Reflection, etc.&lt;/p&gt;&lt;p&gt;But the most common and easy way to create objects in Java is by using new() keyword.&lt;/p&gt;&lt;p&gt;When we create an object of any class in Java, its constructor gets called, which initializes object with its default or initial state.&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/8578422780768054429/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2020/11/what-are-objects-in-object-oriented.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/8578422780768054429'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/8578422780768054429'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2020/11/what-are-objects-in-object-oriented.html' title='What are Objects in Object Oriented Programming aka OOP?'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-8571313591575442060</id><published>2020-10-22T13:00:00.001+05:30</published><updated>2021-01-23T13:03:06.762+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="assembler directives"/><category scheme="http://www.blogger.com/atom/ns#" term="SPOS lab"/><category scheme="http://www.blogger.com/atom/ns#" term="system programming"/><title type='text'>Implement Pass-II of two pass assembler for pseudo-machine in Java using object oriented features. The output of assignment-1 (intermediate file and symbol table) should be input for this assignment.</title><content type='html'>&lt;p&gt;&amp;nbsp;/*&lt;/p&gt;&lt;p&gt;Problem Statement: Implement Pass-II of two pass assembler for pseudo-machine in Java using object oriented&lt;/p&gt;&lt;p&gt;features. The output of assignment-1 (intermediate file and symbol table) should be&lt;/p&gt;&lt;p&gt;input for this assignment.&lt;/p&gt;&lt;p&gt;*/&lt;/p&gt;&lt;p&gt;import java.io.BufferedReader;&lt;/p&gt;&lt;p&gt;import java.io.FileReader;&lt;/p&gt;&lt;p&gt;import java.io.FileWriter;&lt;/p&gt;&lt;p&gt;import java.io.IOException;&lt;/p&gt;&lt;p&gt;import java.util.HashMap;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;public class Pass2 {&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;public static void main(String[] Args) throws IOException{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; BufferedReader b1 = new BufferedReader(new FileReader(&quot;intermediate.txt&quot;));&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;BufferedReader b2 = new BufferedReader(new FileReader(&quot;symtab.txt&quot;));&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;BufferedReader b3 = new BufferedReader(new FileReader(&quot;littab.txt&quot;));&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;FileWriter f1 = new FileWriter(&quot;Pass2.txt&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;HashMap&amp;lt;Integer, String&amp;gt; symSymbol = new HashMap&amp;lt;Integer, String&amp;gt;();&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;HashMap&amp;lt;Integer, String&amp;gt; litSymbol = new HashMap&amp;lt;Integer, String&amp;gt;();&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;HashMap&amp;lt;Integer, String&amp;gt; litAddr = new HashMap&amp;lt;Integer, String&amp;gt;();&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;String s;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;int symtabPointer=1,littabPointer=1,offset;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;while((s=b2.readLine())!=null){&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; String word[]=s.split(&quot;\t\t\t&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; symSymbol.put(symtabPointer++,word[1]);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;while((s=b3.readLine())!=null){&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; String word[]=s.split(&quot;\t\t&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; litSymbol.put(littabPointer,word[0]);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; litAddr.put(littabPointer++,word[1]);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;while((s=b1.readLine())!=null){&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; if(s.substring(1,6).compareToIgnoreCase(&quot;IS,00&quot;)==0){&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; f1.write(&quot;+ 00 0 000\n&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; }&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; else if(s.substring(1,3).compareToIgnoreCase(&quot;IS&quot;)==0){&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; f1.write(&quot;+ &quot;+s.substring(4,6)+&quot; &quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; if(s.charAt(9)==&#39;)&#39;){&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt; f1.write(s.charAt(8)+&quot; &quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt; offset=3;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; }&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; else{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt; f1.write(&quot;0 &quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt; offset=0;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; }&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; if(s.charAt(8+offset)==&#39;S&#39;)&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt; f1.write(symSymbol.get(Integer.parseInt(s.substring(10+offset,s.length()-1)))+&quot;\n&quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt; else&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; &lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt; f1.write(litAddr.get(Integer.parseInt(s.substring(10+offset,s.length()-1)))+&quot;\n&quot;);&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; else if(s.substring(1,6).compareToIgnoreCase(&quot;DL,01&quot;)==0){&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; String s1=s.substring(10,s.length()-1),s2=&quot;&quot;;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; for(int i=0;i&amp;lt;3-s1.length();i++)&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt; s2+=&quot;0&quot;;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; s2+=s1;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; f1.write(&quot;+ 00 0 &quot;+s2+&quot;\n&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; }&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; else{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; f1.write(&quot;\n&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; }&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;f1.close();&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;b1.close();&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;b2.close();&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;b3.close();&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;/*&lt;/p&gt;&lt;p&gt;OUTPUT:&lt;/p&gt;&lt;p&gt;$ javac Pass2.java&amp;nbsp;&lt;/p&gt;&lt;p&gt;$ java Pass2&amp;nbsp;&lt;/p&gt;&lt;p&gt;$ cat Pass2.txt&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;intermediate code -&amp;nbsp;&lt;/p&gt;&lt;p&gt;(AD,01)(C,200)&lt;/p&gt;&lt;p&gt;(IS,04)(1)(L,1)&lt;/p&gt;&lt;p&gt;(IS,05)(1)(S,1)&lt;/p&gt;&lt;p&gt;(IS,04)(1)(S,1)&lt;/p&gt;&lt;p&gt;(IS,04)(3)(S,3)&lt;/p&gt;&lt;p&gt;(IS,01)(3)(L,2)&lt;/p&gt;&lt;p&gt;(IS,07)(6)(S,4)&lt;/p&gt;&lt;p&gt;(DL,01)(C,5)&lt;/p&gt;&lt;p&gt;(DL,01)(C,1)&lt;/p&gt;&lt;p&gt;(IS,02)(1)(L,3)&lt;/p&gt;&lt;p&gt;(IS,07)(1)(S,5)&lt;/p&gt;&lt;p&gt;(IS,00)&lt;/p&gt;&lt;p&gt;(AD,03)(S,2)+2&lt;/p&gt;&lt;p&gt;(IS,03)(3)(S,3)&lt;/p&gt;&lt;p&gt;(AD,03)(S,6)+1&lt;/p&gt;&lt;p&gt;(DL,02)(C,1)&lt;/p&gt;&lt;p&gt;(DL,02)(C,1)&lt;/p&gt;&lt;p&gt;(AD,02)&lt;/p&gt;&lt;p&gt;(DL,01)(C,1)&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Symbol Table --&lt;/p&gt;&lt;p&gt;A&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;211&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;1&lt;/p&gt;&lt;p&gt;LOOP&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;202&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;1&lt;/p&gt;&lt;p&gt;B&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;212&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;1&lt;/p&gt;&lt;p&gt;NEXT&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;208&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;1&lt;/p&gt;&lt;p&gt;BACK&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;202&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;1&lt;/p&gt;&lt;p&gt;LAST&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;210&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;1&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;literal table --&lt;/p&gt;&lt;p&gt;5&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;206&lt;/p&gt;&lt;p&gt;1&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;207&lt;/p&gt;&lt;p&gt;1&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;213&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;machine code --&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;+ 04 1 206&lt;/p&gt;&lt;p&gt;+ 05 1 211&lt;/p&gt;&lt;p&gt;+ 04 1 211&lt;/p&gt;&lt;p&gt;+ 04 3 212&lt;/p&gt;&lt;p&gt;+ 01 3 207&lt;/p&gt;&lt;p&gt;+ 07 6 208&lt;/p&gt;&lt;p&gt;+ 00 0 005&lt;/p&gt;&lt;p&gt;+ 00 0 001&lt;/p&gt;&lt;p&gt;+ 02 1 213&lt;/p&gt;&lt;p&gt;+ 07 1 202&lt;/p&gt;&lt;p&gt;+ 00 0 000&lt;/p&gt;&lt;p&gt;+ 03 3 212&amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/8571313591575442060/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2020/10/implement-pass-ii-of-two-pass-assembler.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/8571313591575442060'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/8571313591575442060'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2020/10/implement-pass-ii-of-two-pass-assembler.html' title='Implement Pass-II of two pass assembler for pseudo-machine in Java using object oriented features. The output of assignment-1 (intermediate file and symbol table) should be input for this assignment.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-3456526483932699537</id><published>2020-09-15T12:55:00.005+05:30</published><updated>2021-01-23T13:09:52.660+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="assembler directives"/><category scheme="http://www.blogger.com/atom/ns#" term="system programming"/><title type='text'>Design suitable data structures and implement pass-I of a two-pass assembler for pseudo-machine in Java using object oriented feature. Implementation should consist of a few instructions from each category and few assembler directives.</title><content type='html'>&lt;p&gt;&amp;nbsp;/*&lt;/p&gt;&lt;p&gt;Problem Statement: Design suitable data structures and implement pass-I of a two-pass assembler for pseudo-&lt;/p&gt;&lt;p&gt;machine in Java using object oriented feature. Implementation should consist of a few&lt;/p&gt;&lt;p&gt;instructions from each category and few assembler directives.&lt;/p&gt;&lt;p&gt;*/&lt;/p&gt;&lt;p&gt;import java.io.*;&lt;/p&gt;&lt;p&gt;class SymTab&lt;/p&gt;&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;public static void main(String args[])throws Exception&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;FileReader FP=new FileReader(args[0]);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;BufferedReader bufferedReader = new BufferedReader(FP);&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;String line=null;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;int line_count=0,LC=0,symTabLine=0,opTabLine=0,litTabLine=0,poolTabLine=0;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; //Data Structures&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; final int MAX=100;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; String SymbolTab[][]=new String[MAX][3];&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; String OpTab[][]=new String[MAX][3];&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; String LitTab[][]=new String[MAX][2];&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; int PoolTab[]=new int[MAX];&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; int litTabAddress=0;&lt;/p&gt;&lt;p&gt;/*---------------------------------------------------------------------------------------------------*/&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt; System.out.println(&quot;___________________________________________________&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp; &amp;nbsp; while((line = bufferedReader.readLine()) != null)&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; String[] tokens = line.split(&quot;\t&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;if(line_count==0)&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;LC=Integer.parseInt(tokens[2]);&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;&lt;/p&gt;&lt;p&gt;//set LC to operand of START&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;for(int i=0;i&amp;lt;tokens.length;i++)&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;//for printing the input program&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; &lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;System.out.print(tokens[i]+&quot;\t&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;System.out.println(&quot;&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;else&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; for(int i=0;i&amp;lt;tokens.length;i++) //for printing the input program&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; &lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;System.out.print(tokens[i]+&quot;\t&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt; System.out.println(&quot;&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;if(!tokens[0].equals(&quot;&quot;))&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;//Inserting into Symbol Table&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;SymbolTab[symTabLine][0]=tokens[0];&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;SymbolTab[symTabLine][1]=Integer.toString(LC);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;SymbolTab[symTabLine][2]=Integer.toString(1);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;symTabLine++;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;else if(tokens[1].equalsIgnoreCase(&quot;DS&quot;)||tokens[1].equalsIgnoreCase(&quot;DC&quot;))&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;//Entry into symbol table for declarative statements&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;SymbolTab[symTabLine][0]=tokens[0];&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;SymbolTab[symTabLine][1]=Integer.toString(LC);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;SymbolTab[symTabLine][2]=Integer.toString(1);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;symTabLine++;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;}&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;if(tokens.length==3 &amp;amp;&amp;amp; tokens[2].charAt(0)==&#39;=&#39;)&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;//Entry of literals into literal table&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;LitTab[litTabLine][0]=tokens[2];&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;LitTab[litTabLine][1]=Integer.toString(LC);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;litTabLine++;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;}&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;else if(tokens[1]!=null)&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;						&lt;/span&gt;//Entry of Mnemonic in opcode table&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;OpTab[opTabLine][0]=tokens[1];&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;if(tokens[1].equalsIgnoreCase(&quot;START&quot;)||tokens[1].equalsIgnoreCase(&quot;END&quot;)||tokens[1].equalsIgnoreCase(&quot;ORIGIN&quot;)||tokens[1].equalsIgnoreCase(&quot;EQU&quot;)||tokens[1].equalsIgnoreCase(&quot;LTORG&quot;))&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;//if Assembler Directive&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;OpTab[opTabLine][1]=&quot;AD&quot;;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;						&lt;/span&gt;OpTab[opTabLine][2]=&quot;R11&quot;;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;}&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;else if(tokens[1].equalsIgnoreCase(&quot;DS&quot;)||tokens[1].equalsIgnoreCase(&quot;DC&quot;))&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;						&lt;/span&gt;OpTab[opTabLine][1]=&quot;DL&quot;;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;						&lt;/span&gt;OpTab[opTabLine][2]=&quot;R7&quot;;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;}&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;else&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;						&lt;/span&gt;OpTab[opTabLine][1]=&quot;IS&quot;;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;						&lt;/span&gt;OpTab[opTabLine][2]=&quot;(04,1)&quot;;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;}&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;opTabLine++;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;}&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; line_count++;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LC++;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp; &amp;nbsp; }&amp;nbsp; &amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;___________________________________________________&quot;);&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;//print symbol table&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;\n\n&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;SYMBOL TABLE&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;--------------------------&quot;);&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;SYMBOL\tADDRESS\tLENGTH&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;--------------------------&quot;);&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;for(int i=0;i&amp;lt;symTabLine;i++)&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;System.out.println(SymbolTab[i][0]+&quot;\t&quot;+SymbolTab[i][1]+&quot;\t&quot;+SymbolTab[i][2]);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;--------------------------&quot;);&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;//print opcode table&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;\n\n&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;OPCODE TABLE&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;----------------------------&quot;);&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;MNEMONIC\tCLASS\tINFO&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;----------------------------&quot;);&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;for(int i=0;i&amp;lt;opTabLine;i++)&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;System.out.println(OpTab[i][0]+&quot;\t\t&quot;+OpTab[i][1]+&quot;\t&quot;+OpTab[i][2]);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;----------------------------&quot;);&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;//print literal table&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;\n\n&amp;nbsp; &amp;nbsp;LITERAL TABLE&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;-----------------&quot;);&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;LITERAL\tADDRESS&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;-----------------&quot;);&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;for(int i=0;i&amp;lt;litTabLine;i++)&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;System.out.println(LitTab[i][0]+&quot;\t&quot;+LitTab[i][1]);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;------------------&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;//intialization of POOLTAB&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;for(int i=0;i&amp;lt;litTabLine;i++)&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;if(LitTab[i][0]!=null &amp;amp;&amp;amp; LitTab[i+1][0]!=null ) //if literals are present&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;if(i==0)&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;{&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;						&lt;/span&gt;PoolTab[poolTabLine]=i+1;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;						&lt;/span&gt;poolTabLine++;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;}&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;else if(Integer.parseInt(LitTab[i][1])&amp;lt;(Integer.parseInt(LitTab[i+1][1]))-1)&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;{&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;						&lt;/span&gt;PoolTab[poolTabLine]=i+2;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;						&lt;/span&gt;poolTabLine++;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;					&lt;/span&gt;}&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;}&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;}&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;//print pool table&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;\n\n&amp;nbsp; &amp;nbsp;POOL TABLE&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;-----------------&quot;);&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;LITERAL NUMBER&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;-----------------&quot;);&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;for(int i=0;i&amp;lt;poolTabLine;i++)&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;				&lt;/span&gt;System.out.println(PoolTab[i]);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;System.out.println(&quot;------------------&quot;);&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;			&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp; &amp;nbsp; // Always close files.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&amp;nbsp; &amp;nbsp; bufferedReader.close();&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;}&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;/*&lt;/p&gt;&lt;p&gt;OUTPUT-&lt;/p&gt;&lt;p&gt;$ javac SymTab.java&amp;nbsp;&lt;/p&gt;&lt;p&gt;$ java SymTab input.txt&lt;/p&gt;&lt;p&gt;___________________________________________________&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;START&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;100&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;READ&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;A&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;LABLE&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;MOVER&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;A,B&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;LTORG&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;=&#39;5&#39;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;=&#39;1&#39;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;=&#39;6&#39;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;=&#39;7&#39;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;MOVEM&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;A,B&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;LTORG&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;=&#39;2&#39;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;LOOP&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;READ&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;B&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;A&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;DS&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;1&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;B&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;DC&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&#39;1&#39;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;=&#39;1&#39;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;END&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;&lt;/p&gt;&lt;p&gt;___________________________________________________&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;SYMBOL TABLE&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;--------------------------&lt;/p&gt;&lt;p&gt;SYMBOL&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;ADDRESS&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;LENGTH&lt;/p&gt;&lt;p&gt;--------------------------&lt;/p&gt;&lt;p&gt;LABLE&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;102&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;1&lt;/p&gt;&lt;p&gt;LOOP&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;111&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;1&lt;/p&gt;&lt;p&gt;A&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;112&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;1&lt;/p&gt;&lt;p&gt;B&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;113&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;1&lt;/p&gt;&lt;p&gt;--------------------------&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;OPCODE TABLE&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;----------------------------&lt;/p&gt;&lt;p&gt;MNEMONIC&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;CLASS&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;INFO&lt;/p&gt;&lt;p&gt;----------------------------&lt;/p&gt;&lt;p&gt;READ&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;IS&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;(04,1)&lt;/p&gt;&lt;p&gt;MOVER&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;IS&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;(04,1)&lt;/p&gt;&lt;p&gt;LTORG&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;AD&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;R11&lt;/p&gt;&lt;p&gt;MOVEM&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;IS&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;(04,1)&lt;/p&gt;&lt;p&gt;LTORG&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;AD&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;R11&lt;/p&gt;&lt;p&gt;READ&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;IS&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;(04,1)&lt;/p&gt;&lt;p&gt;DS&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;DL&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;R7&lt;/p&gt;&lt;p&gt;DC&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;DL&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;R7&lt;/p&gt;&lt;p&gt;END&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;AD&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;R11&lt;/p&gt;&lt;p&gt;----------------------------&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp;LITERAL TABLE&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;-----------------&lt;/p&gt;&lt;p&gt;LITERAL&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;ADDRESS&lt;/p&gt;&lt;p&gt;-----------------&lt;/p&gt;&lt;p&gt;=&#39;5&#39;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;104&lt;/p&gt;&lt;p&gt;=&#39;1&#39;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;105&lt;/p&gt;&lt;p&gt;=&#39;6&#39;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;106&lt;/p&gt;&lt;p&gt;=&#39;7&#39;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;107&lt;/p&gt;&lt;p&gt;=&#39;2&#39;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;110&lt;/p&gt;&lt;p&gt;=&#39;1&#39;&lt;span style=&quot;white-space: pre;&quot;&gt;	&lt;/span&gt;114&lt;/p&gt;&lt;p&gt;------------------&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp;POOL TABLE&lt;span style=&quot;white-space: pre;&quot;&gt;		&lt;/span&gt;&lt;/p&gt;&lt;p&gt;-----------------&lt;/p&gt;&lt;p&gt;LITERAL NUMBER&lt;/p&gt;&lt;p&gt;-----------------&lt;/p&gt;&lt;p&gt;1&lt;/p&gt;&lt;p&gt;5&lt;/p&gt;&lt;p&gt;6&lt;/p&gt;&lt;p&gt;------------------&lt;/p&gt;&lt;p&gt;*/&lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/3456526483932699537/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2020/09/implement-pass-I-of-a-two-pass-assembler-for-pseudo-machine-in-Java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/3456526483932699537'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/3456526483932699537'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2020/09/implement-pass-I-of-a-two-pass-assembler-for-pseudo-machine-in-Java.html' title='Design suitable data structures and implement pass-I of a two-pass assembler for pseudo-machine in Java using object oriented feature. Implementation should consist of a few instructions from each category and few assembler directives.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-3531270375218224296</id><published>2020-07-05T23:07:00.002+05:30</published><updated>2020-07-05T23:07:54.034+05:30</updated><title type='text'>Print all pairs with given sum</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #343434; font-family: &amp;quot;lato&amp;quot; , sans-serif; font-size: 16px;&quot;&gt;Find all pairs of an integer array whose sum is equal to a given number&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
&lt;br /&gt;
//Java implementation of&lt;br /&gt;
// simple method to find&lt;br /&gt;
// print pairs with given sum.&lt;br /&gt;
&lt;br /&gt;
class FindPairsN{&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// Returns number of pairs&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// in arr[0..n-1] with sum&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// equal to &#39;sum&#39;&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;static void getPairs(int arr[],&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;      &lt;/span&gt;int n, int sum)&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;// int count = 0;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;// Consider all possible pairs&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;// and check their sums&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;for (int i = 0; i &amp;lt; n; i++)&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;for (int j = i + 1; j &amp;lt; n; j++)&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;    &lt;/span&gt;if (arr[i] + arr[j] == sum)&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;     &lt;/span&gt;System.out.println(&quot;(&quot; + arr[i] + &quot;, &quot; + arr[j] + &quot;)&quot;);&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// Main&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static void main(String[] arg)&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;int arr[] = { 1, 5, 7, -1, 5 };&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;int n = arr.length;&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;int sum = 6;&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;getPairs(arr, n, sum);&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/3531270375218224296/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2020/07/print-all-pairs-with-given-sum.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/3531270375218224296'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/3531270375218224296'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2020/07/print-all-pairs-with-given-sum.html' title='Print all pairs with given sum'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-5290115499665935369</id><published>2020-07-04T18:59:00.003+05:30</published><updated>2020-07-04T18:59:55.410+05:30</updated><title type='text'>SE- OOP Practical Lab -Implement a class Complex which represents the Complex Number data type.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Implement a class Complex which represents the Complex Number data type.&lt;br /&gt;
Implement
the following operations:&lt;br /&gt;
&amp;nbsp;1. Constructor (including a default constructor which creates the complex number
0+0i).&lt;br /&gt;
&amp;nbsp;2. Overloaded operator+ to add two complex numbers.&lt;br /&gt;
&amp;nbsp;3. Overloaded operator* to multiply two complex numbers.&lt;br /&gt;
&amp;nbsp;4. Overloaded &amp;lt;&amp;lt; and &amp;gt;&amp;gt; to print and read Complex Numbers.&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
&lt;br /&gt;
#include&amp;lt;iostream&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
class complex&lt;br /&gt;
{&lt;br /&gt;
float x;&lt;br /&gt;
float y;&lt;br /&gt;
public:&lt;br /&gt;
&amp;nbsp;complex()&lt;br /&gt;
{&lt;br /&gt;
x=0;&lt;br /&gt;
y=0;&lt;br /&gt;
}&lt;br /&gt;
complex operator+(complex);&lt;br /&gt;
complex operator*(complex);&lt;br /&gt;
friend istream &amp;amp;operator &amp;gt;&amp;gt;(istream &amp;amp;input,complex &amp;amp;t)&lt;br /&gt;
{&lt;br /&gt;
cout&amp;lt;&amp;lt;&quot;Enter the real part&quot;;&lt;br /&gt;
input&amp;gt;&amp;gt;t.x;&lt;br /&gt;
cout&amp;lt;&amp;lt;&quot;Enter the imaginary part&quot;;&lt;br /&gt;
input&amp;gt;&amp;gt;t.y;&lt;br /&gt;
}&lt;br /&gt;
friend ostream &amp;amp;operator &amp;lt;&amp;lt;(ostream &amp;amp;output,complex &amp;amp;t)&lt;br /&gt;
{&lt;br /&gt;
output&amp;lt;&amp;lt;t.x&amp;lt;&amp;lt;&quot;+&quot;&amp;lt;&amp;lt;t.y&amp;lt;&amp;lt;&quot;i\n&quot;;&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
complex complex::operator+(complex c)&lt;br /&gt;
{&lt;br /&gt;
complex temp;&lt;br /&gt;
temp.x=x+c.x;&lt;br /&gt;
temp.y=y+c.y;&lt;br /&gt;
return(temp);&lt;br /&gt;
}&lt;br /&gt;
complex complex::operator*(complex c)&lt;br /&gt;
{&lt;br /&gt;
complex temp2;&lt;br /&gt;
temp2.x=(x*c.x)-(y*c.y);&lt;br /&gt;
temp2.y=(y*c.x)+(x*c.y);&lt;br /&gt;
return (temp2);&lt;br /&gt;
}&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
complex c1,c2,c3,c4;&lt;br /&gt;
&amp;nbsp;cout&amp;lt;&amp;lt;&quot;Default constructor value=\n&quot;;&lt;br /&gt;
&amp;nbsp;cout&amp;lt;&amp;lt;c1;&lt;br /&gt;
cout&amp;lt;&amp;lt;&quot;\nEnter the 1st number\n&quot;;&lt;br /&gt;
cin&amp;gt;&amp;gt;c1;&lt;br /&gt;
cout&amp;lt;&amp;lt;&quot;\nEnter the 2nd number\n&quot;;&lt;br /&gt;
cin&amp;gt;&amp;gt;c2;&lt;br /&gt;
c3=c1+c2;&lt;br /&gt;
c4=c1*c2;&lt;br /&gt;
cout&amp;lt;&amp;lt;&quot;\nThe first number is &quot;;&lt;br /&gt;
cout&amp;lt;&amp;lt;c1;&lt;br /&gt;
cout&amp;lt;&amp;lt;&quot;\nThe second number is &quot;;&lt;br /&gt;
cout&amp;lt;&amp;lt;c2;&lt;br /&gt;
cout&amp;lt;&amp;lt;&quot;\nThe addition is &quot;;&lt;br /&gt;
cout&amp;lt;&amp;lt;c3;&lt;br /&gt;
cout&amp;lt;&amp;lt;&quot;\nThe multiplication is &quot;;&lt;br /&gt;
cout&amp;lt;&amp;lt;c4;&lt;br /&gt;
return 0;&lt;br /&gt;
}&lt;br /&gt;
/*&lt;br /&gt;
student@student-sb:~$ ./a.out&lt;br /&gt;
Default constructor value=&lt;br /&gt;
0+0i&lt;br /&gt;
Enter the 1st number&lt;br /&gt;
Enter the real part2&lt;br /&gt;
Enter the imaginary part4&lt;br /&gt;
Enter the 2nd number&lt;br /&gt;
Enter the real part4&lt;br /&gt;
Enter the imaginary part8&lt;br /&gt;
The first number is 2+4i&lt;br /&gt;
The second number is 4+8i&lt;br /&gt;
The addition is 6+12i&lt;br /&gt;
The multiplication is -24+32i&lt;br /&gt;
student@student-sb:~$
*/&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/5290115499665935369/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2020/07/se-oop-practical-lab-implement-class.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/5290115499665935369'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/5290115499665935369'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2020/07/se-oop-practical-lab-implement-class.html' title='SE- OOP Practical Lab -Implement a class Complex which represents the Complex Number data type.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-3625433958429839647</id><published>2020-07-04T18:37:00.001+05:30</published><updated>2020-07-04T18:42:09.794+05:30</updated><title type='text'>Find missing number.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Find missing number from given range of 1 to n.&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;&lt;strong style=&quot;background-color: white; border: 0px; box-sizing: border-box; color: rgba(0, 0, 0, 0.84); font-size: 16px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Algorithm:&lt;/strong&gt;&lt;span style=&quot;background-color: white; color: rgba(0 , 0 , 0 , 0.84); font-size: 16px;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;ol style=&quot;background-color: white; border: 0px; box-sizing: border-box; color: rgba(0, 0, 0, 0.84); font-size: 16px; line-height: 1.71429; list-style-image: initial; list-style-position: outside; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;border: 0px; box-sizing: border-box; line-height: 1.58; margin: 0px 0px 0px 36px; padding: 0px; text-align: left; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;Calculate the sum of first n natural numbers as&amp;nbsp;&lt;i style=&quot;border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;total= n*(n+1)/2&lt;/i&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: border-box; line-height: 1.58; margin: 0px 0px 0px 36px; padding: 0px; text-align: left; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;create a variable sum to store the sum of array elements.&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: border-box; line-height: 1.58; margin: 0px 0px 0px 36px; padding: 0px; text-align: left; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;Traverse the array from start to end.&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: border-box; line-height: 1.58; margin: 0px 0px 0px 36px; padding: 0px; text-align: left; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;Update the value of sum as&amp;nbsp;&lt;i style=&quot;border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;sum = sum + array[i]&lt;/i&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;border: 0px; box-sizing: border-box; line-height: 1.58; margin: 0px 0px 0px 36px; padding: 0px; text-align: left; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;georgia&amp;quot; , &amp;quot;times new roman&amp;quot; , serif;&quot;&gt;print the missing number as&amp;nbsp;&lt;i style=&quot;border: 0px; box-sizing: border-box; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;total – sum&lt;/i&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
// Java program to find missing Number&lt;br /&gt;
&lt;br /&gt;
class Main {&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// Function to find missing number&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;static int findMissingNo(int a[], int n)&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;int i, total;&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;total = (n + 1) * (n + 2) / 2;//calculates total for original range&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;for (i = 0; i &amp;lt; n; i++)&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;total -= a[i];//this will yield the missing number by continuously subtracting elements&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return total; // from total&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;/* program to test above function */&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static void main(String args[])&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;int a[] = { 1, 2, 4, 5, 6, 7, 8 };&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;int miss = findMissingNo(a, 7 );&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(miss);&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
}&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/3625433958429839647/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2020/07/find-missing-number.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/3625433958429839647'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/3625433958429839647'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2020/07/find-missing-number.html' title='Find missing number.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-1710472935916563664</id><published>2020-07-02T17:06:00.001+05:30</published><updated>2020-07-02T17:10:27.680+05:30</updated><title type='text'>Convert Decimal to Binary. (using recursion)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Convert Decimal to Binary. (using recursion)&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;img alt=&quot;Decimal to Binary Conversion Methods - Examples &amp;amp; Explanation ...&quot; src=&quot;https://circuitglobe.com/wp-content/uploads/2016/09/decimal-to-binary-conversion-example-1.jpg&quot; /&gt;&lt;br /&gt;
&lt;br /&gt;
import java.util.*;&lt;br /&gt;
&lt;br /&gt;
public class DecimalToBinary {&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static void main(String[] args) {&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;// TODO Auto-generated method stub&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Scanner sc= new Scanner(System.in);&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;Enter a valid integer:&quot;);&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;while(sc.hasNextInt())&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;int a=sc.nextInt();&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;printbinary(a);&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;System.out.println(&quot;\nEnter a bumber, press q to exit!&quot;);&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;sc.close();&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static void printbinary(int b)&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(b&amp;gt;0)&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;printbinary(b/2);&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;System.out.printf(&quot;%d&quot;, b%2);&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
}&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/1710472935916563664/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2020/07/convert-decimal-to-binary-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/1710472935916563664'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/1710472935916563664'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2020/07/convert-decimal-to-binary-using.html' title='Convert Decimal to Binary. (using recursion)'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-3736183493560140962</id><published>2020-07-02T16:19:00.003+05:30</published><updated>2020-07-02T16:19:43.007+05:30</updated><title type='text'>Reverse a linked list. (Using recursion)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Reverse a linked list using recursion using Java.&lt;br /&gt;
&lt;br /&gt;
Solution:&lt;br /&gt;
&lt;br /&gt;
public class Node {&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int data;&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Node next;&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public Node(int a, Node next)&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;this.data= a;&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;this.next = next;&lt;br /&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
public class Linkedlist {&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static void main(String[] args) {&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;// TODO Auto-generated method stub&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Node node1= new Node(1,null);&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Node node2= new Node(2, null);&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Node node3= new Node(3, null);&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;node1.next=node2;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;node2.next=node3;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;node3.next=null;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printlist(node1);&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;\n*********&quot;);&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;printreverse(node1);&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static void printlist(Node n)&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(n!=null)&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;System.out.print(&quot; &quot; + n.data);//will print in order&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;printlist(n.next);&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static void printreverse(Node n)&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;{&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(n!=null)&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;{&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;printreverse(n.next);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// will stack the nested calls and return the output in reverse order&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;//as per stack property calls will be stacked and the last one will be returned first&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;System.out.print(&quot; &quot;+n.data);&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/3736183493560140962/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2020/07/reverse-linked-list-using-recursion.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/3736183493560140962'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/3736183493560140962'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2020/07/reverse-linked-list-using-recursion.html' title='Reverse a linked list. (Using recursion)'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-3343337592740164224</id><published>2020-06-28T23:34:00.000+05:30</published><updated>2020-06-28T23:35:21.830+05:30</updated><title type='text'>Obtain the sum of the first and last digits of this number.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Write a program to obtain the sum of the first and last digits of this number.


&lt;br /&gt;
&lt;h3 class=&quot; mathjax-support&quot;&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Solution:&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;h3 class=&quot; mathjax-support&quot;&gt;
&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // your code goes here&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int t;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cin&amp;gt;&amp;gt;t;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int i=0; i&amp;lt;t; i++)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; int n;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; cin&amp;gt;&amp;gt;n;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (n&amp;lt;10)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;n&amp;lt;&amp;lt;endl;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; else{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; int last = n%10;// get the last digit&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; while(n&amp;gt;9)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n/=10;// get first digit&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int sum= last+ n;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;sum&amp;lt;&amp;lt;endl;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;br /&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/3343337592740164224/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2020/06/obtain-sum-of-first-and-last-digits-of.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/3343337592740164224'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/3343337592740164224'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2020/06/obtain-sum-of-first-and-last-digits-of.html' title='Obtain the sum of the first and last digits of this number.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-5623339004696430091</id><published>2020-06-28T23:23:00.002+05:30</published><updated>2020-06-28T23:23:25.019+05:30</updated><title type='text'>Sum of digits in the given number.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Write a program to calculate the sum of all the digits of &lt;b class=&quot; mathjax-support&quot;&gt;N&lt;/b&gt;. N is an integer.&lt;br /&gt;
&lt;br /&gt;
&lt;h3 class=&quot; mathjax-support&quot;&gt;
Input&lt;/h3&gt;
&lt;div class=&quot; mathjax-support&quot;&gt;
 
The first line contains an integer &lt;b class=&quot; mathjax-support&quot;&gt;T&lt;/b&gt;, the total number of testcases. Then follow &lt;b class=&quot; mathjax-support&quot;&gt;T&lt;/b&gt; lines, each line contains an integer &lt;b class=&quot; mathjax-support&quot;&gt;N&lt;/b&gt;. 
&lt;/div&gt;
&lt;br /&gt;
&lt;h3 class=&quot; mathjax-support&quot;&gt;
Output&lt;/h3&gt;
&lt;div class=&quot; mathjax-support&quot;&gt;
 For each test case, calculate the sum of digits of &lt;b class=&quot; mathjax-support&quot;&gt;N&lt;/b&gt;, and display it in a new line.&lt;/div&gt;
&lt;h3 class=&quot; mathjax-support&quot;&gt;
Constraints&lt;/h3&gt;
&lt;ul class=&quot; mathjax-support&quot;&gt;
&lt;li class=&quot; mathjax-support&quot;&gt;1 &lt;b class=&quot; mathjax-support&quot;&gt;≤&lt;/b&gt; &lt;b class=&quot; mathjax-support&quot;&gt;T&lt;/b&gt; &lt;b class=&quot; mathjax-support&quot;&gt;≤&lt;/b&gt; 1000&lt;/li&gt;
&lt;li class=&quot; mathjax-support&quot;&gt;1 &lt;b class=&quot; mathjax-support&quot;&gt;≤&lt;/b&gt; &lt;b class=&quot; mathjax-support&quot;&gt;N&lt;/b&gt; &lt;b class=&quot; mathjax-support&quot;&gt;≤&lt;/b&gt; 1000000&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 class=&quot; mathjax-support&quot;&gt;
Example&lt;/h3&gt;
&lt;pre class=&quot; mathjax-support&quot;&gt;&lt;b class=&quot; mathjax-support&quot;&gt;Input&lt;/b&gt;
3 
12345
31203
2123
&lt;b class=&quot; mathjax-support&quot;&gt;Output&lt;/b&gt;
15
9
8
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Solution:&lt;/b&gt;&lt;br /&gt;
&amp;nbsp;C++:&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;using namespace std;&lt;br /&gt;&lt;br /&gt;int main() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // your code goes here&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int t;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cin&amp;gt;&amp;gt;t;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for(int i=0; i&amp;lt;t; i++)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; int n;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; cin&amp;gt;&amp;gt;n;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; int sum=0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while(n&amp;gt;0)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; sum+=n%10;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; n/=10;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cout&amp;lt;&amp;lt;sum&amp;lt;&amp;lt;endl;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;br /&gt;}&lt;br /&gt;
&lt;br /&gt;
******************************************************************************&lt;br /&gt;
JAVA:&lt;br /&gt;
&lt;br /&gt;
import java.util.*;&lt;br /&gt;import java.lang.*;&lt;br /&gt;import java.io.*;&lt;br /&gt;&lt;br /&gt;/* Name of the class has to be &quot;Main&quot; only if the class is public. */&lt;br /&gt;class Codechef&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; static int sum (int n){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; if (n == 0){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0 ;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; return n % 10 + sum(n/10) ;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main (String[] args) throws java.lang.Exception&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; // your code goes here&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Scanner sc = new Scanner(System.in);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; int t = sc.nextInt();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; while(t--&amp;gt;0){&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; int n = sc.nextInt();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(sum(n));&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;*******************************************************************************&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/5623339004696430091/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2020/06/sum-of-digits-in-given-number.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/5623339004696430091'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/5623339004696430091'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2020/06/sum-of-digits-in-given-number.html' title='Sum of digits in the given number.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-2919416362790634320</id><published>2018-04-08T18:31:00.002+05:30</published><updated>2018-04-08T18:31:41.072+05:30</updated><title type='text'>Java program for Safe Sequence (Banker&#39;s Algorithm).</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;pre class=&quot;aLF-aPX-K0-aPE&quot; style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace, arial, sans-serif; font-size: 14px; user-select: text; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;//Java program for safe sequence of Banker&#39;s algorithm.&lt;/pre&gt;
&lt;pre class=&quot;aLF-aPX-K0-aPE&quot; style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace, arial, sans-serif; font-size: 14px; user-select: text; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;
&lt;/pre&gt;
&lt;pre class=&quot;aLF-aPX-K0-aPE&quot; style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace, arial, sans-serif; font-size: 14px; user-select: text; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;import java.util.*;
class SafeAlgo
{
 public static void main(String args[])
 {
  Scanner sc=new Scanner(System.in);
  System.out.println(&quot;Enter number of processes:&quot;);
  int n=sc.nextInt();
  int p[]=new int[n];
  int flag[]=new int[n];
  System.out.println(&quot;Enter number of resource variables&quot;);
  int m=sc.nextInt();
  
  int max[][]=new int[n][m];
  int allo[][]=new int[n][m];
  int need[][]=new int[n][m];
  int avail[]=new int[m];
  for(int x=0;x&amp;lt;n;x++)
  {
   System.out.println(&quot;Enter process number:&quot;);
   p[x]=sc.nextInt();
   flag[x]=0;
   for(int y=0;y&amp;lt;m;y++)
   {
    System.out.println(&quot;Max -&amp;gt; P&quot;+p[x]+&quot; -&amp;gt;&quot;+y+&quot; :&quot;);
    max[x][y]=sc.nextInt();    
    
   }
   for(int y=0;y&amp;lt;m;y++)
   {
    System.out.println(&quot;Allocation -&amp;gt; P&quot;+p[x]+&quot; -&amp;gt;&quot;+y+&quot; :&quot;);
    allo[x][y]=sc.nextInt();
    need[x][y]=max[x][y]-allo[x][y];
   }
  }
  System.out.println(&quot;Enter available resources:&quot;);
  for(int y=0;y&amp;lt;m;y++)
   avail[y]=sc.nextInt();
  
  System.out.println(&quot;Process\tMax\tAllocation\tNeed&quot;);
  for(int x=0;x&amp;lt;n;x++)
  {
   System.out.print(&quot;P&quot;+p[x]+&quot;\t&quot;);
   for(int y=0;y&amp;lt;m;y++)
    System.out.print(max[x][y]+&quot; &quot;);
   System.out.print(&quot;\t&quot;);
   for(int y=0;y&amp;lt;m;y++)
    System.out.print(allo[x][y]+&quot; &quot;);
   System.out.print(&quot;\t\t&quot;);
   for(int y=0;y&amp;lt;m;y++)
    System.out.print(need[x][y]+&quot; &quot;);
   System.out.println();
  }
  
  int count=0;
  while(count&amp;lt;=n)
  {
   
    for(int x=0;x&amp;lt;n;x++)
    {
     if(flag[x]==0)
     {
     int f=0;
     for(int y=0;y&amp;lt;m;y++)
     {      
      if(avail[y]&amp;lt;need[x][y])
      {
       f=1;
       break;
      }
     }
       
     if(f==0)
     {
      flag[x]=1;
      for(int y=0;y&amp;lt;m;y++)
      {
       avail[y]+=allo[x][y];
      }
      System.out.println(&quot;P&quot;+p[x]);
      count++;
     }
     }
    }
   }
  }
 }&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/2919416362790634320/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2018/04/java-program-for-safe-sequence-bankers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/2919416362790634320'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/2919416362790634320'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2018/04/java-program-for-safe-sequence-bankers.html' title='Java program for Safe Sequence (Banker&#39;s Algorithm).'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-306464285465768601</id><published>2018-04-08T18:25:00.002+05:30</published><updated>2018-04-08T18:25:38.659+05:30</updated><title type='text'>SJF Scheduling Algorithm Java Implementation.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;pre class=&quot;aLF-aPX-K0-aPE&quot; style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace, arial, sans-serif; font-size: 14px; user-select: text; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;//Java program for Shortest Job First Scheduling algorithm.&lt;/pre&gt;
&lt;pre class=&quot;aLF-aPX-K0-aPE&quot; style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace, arial, sans-serif; font-size: 14px; user-select: text; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;
&lt;/pre&gt;
&lt;pre class=&quot;aLF-aPX-K0-aPE&quot; style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace, arial, sans-serif; font-size: 14px; user-select: text; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;import java.io.*;&lt;/pre&gt;
&lt;pre class=&quot;aLF-aPX-K0-aPE&quot; style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace, arial, sans-serif; font-size: 14px; user-select: text; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;public class SJF{
 public static void main(String args[]) throws IOException
 {
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      int n;
      System.out.println(&quot;Please enter the number of Processes: &quot;);
       n = Integer.parseInt(br.readLine());
       int proc[][] = new int[n + 1][4];
       for(int i = 1; i &amp;lt;= n; i++)
       {
      System.out.println(&quot;Please enter the Arrival Time for Process &quot; + i + &quot;: &quot;);
      proc[i][0] = Integer.parseInt(br.readLine());
      System.out.println(&quot;Please enter the Burst Time for Process &quot; + i + &quot;: &quot;);
      proc[i][1] = Integer.parseInt(br.readLine());
     }
       System.out.println();
     
      
     int total_time = 0;
     for(int i = 1; i &amp;lt;= n; i++)
     {
      total_time += proc[i][1];
     }
     int time_chart[] = new int[total_time];
     
     for(int i = 0; i &amp;lt; total_time; i++)
     {
    
      int sel_proc = 0;
      int min = 99999;
      for(int j = 1; j &amp;lt;= n; j++)
      {
       if(proc[j][0] &amp;lt;= i)
       {
        if(proc[j][1] &amp;lt; min &amp;amp;&amp;amp; proc[j][1] != 0)
        {
         min = proc[j][1];
         sel_proc = j;
        }
       }
      }
      
     
      time_chart[i] = sel_proc;
      
      
      proc[sel_proc][1]--;
      
      
      for(int j = 1; j &amp;lt;= n; j++)
      {
       if(proc[j][0] &amp;lt;= i)
       {
        if(proc[j][1] != 0)
        {
         proc[j][3]++;
            if(j != sel_proc)
             proc[j][2]++;
        }
        else if(j == sel_proc)
         proc[j][3]++;
       }
      }
      
     
      if(i != 0)
      {
       if(sel_proc != time_chart[i - 1])
       
       {
        System.out.print(&quot;--&quot; + i + &quot;--P&quot; + sel_proc);
       }
      }
      else
       System.out.print(i + &quot;--P&quot; + sel_proc);
      if(i == total_time - 1)
       System.out.print(&quot;--&quot; + (i + 1));
      
     }
     System.out.println();
     System.out.println();
     
     
     System.out.println(&quot;P\t WT \t TT &quot;);
     for(int i = 1; i &amp;lt;= n; i++)
     {
      System.out.printf(&quot;%d\t%2dms\t%2dms&quot;,i,proc[i][2],proc[i][3]);
      System.out.println();
     }
     
     System.out.println();
     
    
     float WT = 0,TT = 0;
     for(int i = 1; i &amp;lt;= n; i++)
     {
      WT += proc[i][2];
      TT += proc[i][3];
     }
     WT /= n;
     TT /= n;
     System.out.println(&quot;The Average WT is: &quot; + WT + &quot;ms&quot;);
     System.out.println(&quot;The Average TT is: &quot; + TT + &quot;ms&quot;);
 }
    
}

/*

OUTPUT:

Please enter the number of Processes: 
4
Please enter the Arrival Time for Process 1: 
0
Please enter the Burst Time for Process 1: 
7
Please enter the Arrival Time for Process 2: 
3
Please enter the Burst Time for Process 2: 
3
Please enter the Arrival Time for Process 3: 
5
Please enter the Burst Time for Process 3: 
2
Please enter the Arrival Time for Process 4: 
4
Please enter the Burst Time for Process 4: 
5

0--P1--3--P2--6--P3--8--P1--12--P4--17

P  WT   TT 
1  5ms 12ms
2  0ms  3ms
3  1ms  3ms
4  8ms 13ms

The Average WT is: 3.5ms
The Average TT is: 7.75ms
*/
&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/306464285465768601/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2018/04/sjf-scheduling-algorithm-java.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/306464285465768601'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/306464285465768601'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2018/04/sjf-scheduling-algorithm-java.html' title='SJF Scheduling Algorithm Java Implementation.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-63877335318332703</id><published>2018-04-08T18:20:00.002+05:30</published><updated>2018-04-08T18:20:45.619+05:30</updated><title type='text'>Round Robin Scheduling Algorithm Java Implementation.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;pre class=&quot;aLF-aPX-K0-aPE&quot; style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace, arial, sans-serif; font-size: 14px; user-select: text; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;//Java Program for Round Robin scheduling algorithm.&lt;/pre&gt;
&lt;pre class=&quot;aLF-aPX-K0-aPE&quot; style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace, arial, sans-serif; font-size: 14px; user-select: text; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;import java.io.*;
class rr
{
public static void main(String args[])throws IOException
{
DataInputStream in=new DataInputStream(System.in);
int i,j,k,q,sum=0;
System.out.println(&quot;Enter number of process:&quot;);
int n=Integer.parseInt(in.readLine());
int bt[]=new int[n];
int wt[]=new int[n];
int tat[]=new int[n];
int a[]=new int[n];
System.out.println(&quot;Enter brust Time:&quot;);
for(i=0;i&amp;lt;n;i++)
{
System.out.println(&quot;Enter brust Time for &quot;+(i+1));
bt[i]=Integer.parseInt(in.readLine());
}
System.out.println(&quot;Enter Time quantum:&quot;);
q=Integer.parseInt(in.readLine());
for(i=0;i&amp;lt;n;i++)
a[i]=bt[i];
for(i=0;i&amp;lt;n;i++)
wt[i]=0;
do
{
for(i=0;i&amp;lt;n;i++)
{
if(bt[i]&amp;gt;q)
{
bt[i]-=q;
for(j=0;j&amp;lt;n;j++)
{
if((j!=i)&amp;amp;&amp;amp;(bt[j]!=0))
wt[j]+=q;
}
}
else
{
for(j=0;j&amp;lt;n;j++)
{
if((j!=i)&amp;amp;&amp;amp;(bt[j]!=0))
wt[j]+=bt[i];
}
bt[i]=0;
}
}
sum=0;
for(k=0;k&amp;lt;n;k++)
sum=sum+bt[k];
}
while(sum!=0);
for(i=0;i&amp;lt;n;i++)
tat[i]=wt[i]+a[i];
System.out.println(&quot;process\t\tBT\tWT\tTAT&quot;);
for(i=0;i&amp;lt;n;i++)
{
System.out.println(&quot;process&quot;+(i+1)+&quot;\t&quot;+a[i]+&quot;\t&quot;+wt[i]+&quot;\t&quot;+tat[i]);
}
float avg_wt=0;
float avg_tat=0;
for(j=0;j&amp;lt;n;j++)
{
avg_wt+=wt[j];
}
for(j=0;j&amp;lt;n;j++)
{
avg_tat+=tat[j];
}
System.out.println(&quot;average waiting time &quot;+(avg_wt/n)+&quot;\n Average turn around time&quot;+(avg_tat/n));
}
}



/**********OUTPUT********

Enter number of process:
5
Enter brust Time:
Enter brust Time for 1
7
Enter brust Time for 2
4
Enter brust Time for 3
3
Enter brust Time for 4
8
Enter brust Time for 5
5
Enter Time quantum:
2
process  BT WT TAT
process1 7 18 25
process2 4 10 14
process3 3 12 15
process4 8 19 27
process5 5 19 24
average waiting time 15.6
 Average turn around time21.0


*********************/&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/63877335318332703/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2018/04/round-robin-scheduling-algorithm-java.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/63877335318332703'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/63877335318332703'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2018/04/round-robin-scheduling-algorithm-java.html' title='Round Robin Scheduling Algorithm Java Implementation.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-1136231552184314571</id><published>2018-04-08T18:17:00.001+05:30</published><updated>2018-04-08T18:17:53.921+05:30</updated><title type='text'>Priority Scheduling Algorithm Java Program.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;pre class=&quot;aLF-aPX-K0-aPE&quot; style=&quot;background-color: white; font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace, arial, sans-serif; font-size: 14px; user-select: text; white-space: pre-wrap; word-wrap: break-word;&quot;&gt;import java.util.Scanner;
 
public class priority{
        
    public static void main(String args[]) {
            Scanner s = new Scanner(System.in);
 
            int x,n,p[],pp[],bt[],w[],t[],awt,atat,i;
 
            p = new int[10];
            pp = new int[10];
            bt = new int[10];
            w = new int[10];
            t = new int[10];
 
   //n is number of process
   //p is process
   //pp is process priority
   //bt is process burst time
   //w is wait time
   // t is turnaround time
   //awt is average waiting time
   //atat is average turnaround time
 
 
   System.out.print(&quot;Enter the number of process : &quot;);
   n = s.nextInt();
    System.out.print(&quot;\n\t Enter burst time : time priorities \n&quot;);
 
   for(i=0;i&amp;lt;n;i++)
    {
       System.out.print(&quot;\nProcess[&quot;+(i+1)+&quot;]:&quot;);
      bt[i] = s.nextInt();
      pp[i] = s.nextInt();
      p[i]=i+1;
    }
 
//sorting on the basis of priority
  for(i=0;i&amp;lt;n-1;i++)
   {
     for(int j=i+1;j&amp;lt;n;j++)
     {
       if(pp[i]&amp;gt;pp[j])
       {
     x=pp[i];
     pp[i]=pp[j];
     pp[j]=x;
     x=bt[i];
     bt[i]=bt[j];
     bt[j]=x;
     x=p[i];
     p[i]=p[j];
     p[j]=x;
      }
   }
}
w[0]=0;
awt=0;
t[0]=bt[0];
atat=t[0];
for(i=1;i&amp;lt;n;i++)
 {
   w[i]=t[i-1];
   awt+=w[i];
   t[i]=w[i]+bt[i];
   atat+=t[i];
 }
 
//Displaying the process
 
  System.out.print(&quot;\n\nProcess \t Burst Time \t Wait Time \t Turn Around Time   Priority \n&quot;);
for(i=0;i&amp;lt;n;i++)
  System.out.print(&quot;\n   &quot;+p[i]+&quot;\t\t   &quot;+bt[i]+&quot;\t\t     &quot;+w[i]+&quot;\t\t     &quot;+t[i]+&quot;\t\t     &quot;+pp[i]+&quot;\n&quot;);
awt/=n;
atat/=n;
  System.out.print(&quot;\n Average Wait Time : &quot;+awt);
  System.out.print(&quot;\n Average Turn Around Time : &quot;+atat);
 
        }
}


/*******OUTPUT********

Enter the number of process : 5

  Enter burst time : time priorities 

Process[1]:7 2

Process[2]:6 4

Process[3]:4 1

Process[4]:5 3

Process[5]:1 0


Process   Burst Time   Wait Time   Turn Around Time   Priority 

   5     1       0       1       0

   3     4       1       5       1

   1     7       5       12       2

   4     5       12       17       3

   2     6       17       23       4

 Average Wait Time : 7
 Average Turn Around Time : 11

************************/&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/1136231552184314571/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2018/04/priority-scheduling-algorithm-java.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/1136231552184314571'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/1136231552184314571'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2018/04/priority-scheduling-algorithm-java.html' title='Priority Scheduling Algorithm Java Program.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-2498394184159636368</id><published>2018-04-08T18:13:00.002+05:30</published><updated>2020-11-29T15:38:32.112+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Page Replacement"/><title type='text'>Optimal Page Replacement algorithm in Java.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;pre class=&quot;brush: java&quot; style=&quot;background-color: #f9f9f9; color: #333333; font-size: 14px;&quot;&gt;import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class OptimalReplacement {

    public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int frames, pointer = 0, hit = 0, fault = 0,ref_len;
        boolean isFull = false;
        int buffer[];
        int reference[];
        int mem_layout[][];
        
        System.out.println(&quot;Enter the number of Frames: &quot;);
        frames = Integer.parseInt(br.readLine());
        
        System.out.println(&quot;Enter the length of the Reference string: &quot;);
        ref_len = Integer.parseInt(br.readLine());
        
        reference = new int[ref_len];
        mem_layout = new int[ref_len][frames];
        buffer = new int[frames];
        for(int j = 0; j &amp;lt; frames; j++)
                buffer[j] = -1;
        
        System.out.println(&quot;Enter the reference string: &quot;);
        for(int i = 0; i &amp;lt; ref_len; i++)
        {
            reference[i] = Integer.parseInt(br.readLine());
        }
        System.out.println();
        for(int i = 0; i &amp;lt; ref_len; i++)
        {
         int search = -1;
         for(int j = 0; j &amp;lt; frames; j++)
         {
          if(buffer[j] == reference[i])
          {
           search = j;
           hit++;
           break;
          } 
         }
         if(search == -1)
         {
          if(isFull)
          {
           int index[] = new int[frames];
           boolean index_flag[] = new boolean[frames];
           for(int j = i + 1; j &amp;lt; ref_len; j++)
           {
            for(int k = 0; k &amp;lt; frames; k++)
            {
             if((reference[j] == buffer[k]) &amp;amp;&amp;amp; (index_flag[k] == false))
             {
              index[k] = j;
              index_flag[k] = true;
              break;
             }
            }
           }
           int max = index[0];
           pointer = 0;
           if(max == 0)
            max = 200;
           for(int j = 0; j &amp;lt; frames; j++)
           {
            if(index[j] == 0)
             index[j] = 200;
            if(index[j] &amp;gt; max)
            {
             max = index[j];
             pointer = j;
            }
           }
          }
          buffer[pointer] = reference[i];
          fault++;
          if(!isFull)
          {
           pointer++;
              if(pointer == frames)
              {
               pointer = 0;
               isFull = true;
              }
          }
         }
            for(int j = 0; j &amp;lt; frames; j++)
                mem_layout[i][j] = buffer[j];
        }
        
        for(int i = 0; i &amp;lt; frames; i++)
        {
            for(int j = 0; j &amp;lt; ref_len; j++)
                System.out.printf(&quot;%3d &quot;,mem_layout[j][i]);
            System.out.println();
        }
        
        System.out.println(&quot;The number of Hits: &quot; + hit);
        System.out.println(&quot;Hit Ratio: &quot; + (float)((float)hit/ref_len));
        System.out.println(&quot;The number of Faults: &quot; + fault);
    }
    
}
&lt;/pre&gt;
&lt;b style=&quot;background-color: #f9f9f9; color: #333333; font-family: &amp;quot;Istok Web&amp;quot;, sans-serif; font-size: 14px;&quot;&gt;/*OUTPUT:-&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: csharp&quot; style=&quot;background-color: #f9f9f9; color: #333333; font-size: 14px;&quot;&gt;Please enter the number of Frames: 
3
Please enter the length of the Reference string: 
20
Please enter the reference string: 
1
2
3
2
1
5
2
1
6
2
5
6
3
1
3
6
1
2
4
3

  1   1   1   1   1   1   1   1   6   6   6   6   6   6   6   6   6   2   4   4 
 -1   2   2   2   2   2   2   2   2   2   2   2   2   1   1   1   1   1   1   1 
 -1  -1   3   3   3   5   5   5   5   5   5   5   3   3   3   3   3   3   3   3 
The number of Hits: 11
Hit Ratio: 0.55
The number of Faults: 9&lt;/pre&gt;
&lt;pre class=&quot;brush: csharp&quot; style=&quot;background-color: #f9f9f9; color: #333333; font-size: 14px;&quot;&gt;*/&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/2498394184159636368/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2018/04/optimal-page-replacement-algorithm-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/2498394184159636368'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/2498394184159636368'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2018/04/optimal-page-replacement-algorithm-in.html' title='Optimal Page Replacement algorithm in Java.'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5915261747998938651.post-6424836335314012647</id><published>2018-04-08T18:10:00.000+05:30</published><updated>2020-11-29T15:37:50.803+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="Page Replacement"/><title type='text'>LRU Page Replacement algorithm in Java.(Least Recently Used)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
import java.util.Scanner;&lt;br /&gt;
&lt;br /&gt;
public class lru&lt;br /&gt;
{&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; public static int min(int counter[],int nFrames)&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; int minimum = counter[0];&lt;br /&gt;
&amp;nbsp; &amp;nbsp; int pos = 0;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; for(int i=0;i&amp;lt;nFrames;i++) { if(minimum &amp;gt; counter[i])&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pos = i;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp;return pos;&amp;nbsp; &lt;br /&gt;
}&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; public static void main(String[] args) {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // TODO code application logic here&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Scanner s = new Scanner(System.in);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; int n,recent = 0,pageFault = 0,nFrames;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; System.out.print(&quot;Enter the number of pages: &quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; n = s.nextInt();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; int pageString[] = new int[n];&lt;br /&gt;
&amp;nbsp; &amp;nbsp; System.out.print(&quot;Enter the page reference string: &quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; for(int i=0;i&amp;lt;n;i++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pageString[i]=s.nextInt();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;System.out.print(&quot;\nEnter the number of frames: &quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;nFrames = s.nextInt();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;int frames[] = new int[nFrames];&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;int counter[] = new int[nFrames];&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;for(int i=0;i&amp;lt;nFrames;i++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;{&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; frames[i] = 0;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; counter[i] = 0;//here 0 referes an empty space in frame&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; for(int i=0;i&amp;lt;n;i++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; {int flag =0;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(int j=0;j&amp;lt;nFrames;j++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(frames[j] == pageString[i])&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{flag=1;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; counter[j] = recent++; //counter holds which frame is recently used,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //recently used page in frame will have a bigger number&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //and least recently used page in frame will have a lower number&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;break;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(flag == 0)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(int j=0;j&amp;lt;nFrames;j++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {if(frames[j] == 0)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&amp;nbsp; &amp;nbsp;frames[j] = pageString[i];&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; counter[j] = recent++;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; flag=1;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pageFault++;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if(flag == 0){&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int PositionToreplace = min(counter,nFrames);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; frames[PositionToreplace] = pageString[i];&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; counter[PositionToreplace] = recent++;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; pageFault++;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //print frames&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.out.println();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; for(int j=0;j&amp;lt;nFrames;j++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;System.out.print(frames[j]+&quot; &quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; System.out.print(&quot;\nPage Fault: &quot;+pageFault);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*********OUTPUT******&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Enter the number of pages: 13&lt;br /&gt;
Enter the page reference string: 1&lt;br /&gt;
2&lt;br /&gt;
3&lt;br /&gt;
1&lt;br /&gt;
2&lt;br /&gt;
2&lt;br /&gt;
1&lt;br /&gt;
4&lt;br /&gt;
5&lt;br /&gt;
1&lt;br /&gt;
3&lt;br /&gt;
2&lt;br /&gt;
1&lt;br /&gt;
&lt;br /&gt;
Enter the number of frames: 3&lt;br /&gt;
&lt;br /&gt;
1 0 0&lt;br /&gt;
1 2 0&lt;br /&gt;
1 2 3&lt;br /&gt;
1 2 3&lt;br /&gt;
1 2 3&lt;br /&gt;
1 2 3&lt;br /&gt;
1 2 3&lt;br /&gt;
1 2 4&lt;br /&gt;
1 5 4&lt;br /&gt;
1 5 4&lt;br /&gt;
1 5 3&lt;br /&gt;
1 2 3&lt;br /&gt;
1 2 3&lt;br /&gt;
Page Fault: 7&lt;br /&gt;
*/&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://meetshrikantb.blogspot.com/feeds/6424836335314012647/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://meetshrikantb.blogspot.com/2018/04/lru-page-replacement-algorithm-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/6424836335314012647'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5915261747998938651/posts/default/6424836335314012647'/><link rel='alternate' type='text/html' href='http://meetshrikantb.blogspot.com/2018/04/lru-page-replacement-algorithm-in.html' title='LRU Page Replacement algorithm in Java.(Least Recently Used)'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>