{"id":69,"date":"2019-03-24T23:06:58","date_gmt":"2019-03-24T23:06:58","guid":{"rendered":"https:\/\/avantutor.com\/blog\/?p=69"},"modified":"2020-01-28T01:10:13","modified_gmt":"2020-01-28T01:10:13","slug":"10-simple-java-for-loop-exercises-try-it-right-here","status":"publish","type":"post","link":"https:\/\/avantutor.com\/blog\/10-simple-java-for-loop-exercises-try-it-right-here\/","title":{"rendered":"10 Simple Java For-Loop Exercises"},"content":{"rendered":"\n<p>The following java for-loop exercises have been collected from various internet sources such as programmr.com and codewars. Go to <a rel=\"noreferrer noopener\" aria-label=\"my tutoring page (opens in a new tab)\" href=\"https:\/\/avantutor.com\" target=\"_blank\">my tutoring page<\/a> if you need more help and would like to talk to a tutor. <\/p>\n\n\n\n<p>User input does not work with the embedded compiler (paiza) below. That is why you see the problems being worded and setup slightly differently  than on the rest of the page.<\/p>\n\n\n\n<p>Happy Coding!<\/p>\n\n\n\n<iframe loading=\"lazy\" src=\"https:\/\/paiza.io\/projects\/e\/DSmVkNik59VK3UJyBDqKvA?theme=eclipse\" width=\"100%\" height=\"500\" scrolling=\"no\" seamless=\"seamless\"><\/iframe>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 1: <\/h2>\n\n\n\n<p>Determine and print the number of times the character &#8216;a&#8217; appears in the input entered by the user.<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Program Starts:<\/strong><br>Enter String: <br>This is a test Output: <br><br><strong>Output: <\/strong><br>Number of a's: 1<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 2: <\/h2>\n\n\n\n<p>Write a program that will print a box of #&#8217;s taking from user the height and width values.<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Program Starts: <\/strong> <br>Enter height: <br>7 <br>Enter width: <br>5 <br><br><strong>Output: <\/strong><br>##### <br>##### <br>##### <br>##### <br>##### <br>##### <br>#####<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 3<\/h2>\n\n\n\n<p>Write a program to find the sum of 5 integers.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Program Starts: <\/strong> <br>Enter an integer:<br>2 <br>Enter an integer:<br>4 <br>Enter an integer:<br>3 <br>Enter an integer:<br>-2 <br>Enter an integer:<br>3<br><br><strong>Output: <\/strong><br>Total is: 15<br><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 4<\/h2>\n\n\n\n<p>Write a java program to calculate the factorial value of given number. Factorial x &#8211;&gt; x * x-1 * x-2&#8230;x*1<\/p>\n\n\n\n<p>Example: factorial 4 = 4 * 3 * 2 * 1 = 24<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Program Starts: <\/strong> <br>Enter a number:<br>5 <br><br><strong>Output: <\/strong><br>Factorial of the number is: 120 <br><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 5<\/h2>\n\n\n\n<p>Suppose we have a database composed of two fields or columns (arrays), the first field is for the username (user[]) and the other one is for the password(pass[]) .<\/p>\n\n\n\n<p>This is how it looks like:<\/p>\n\n\n\n<p>user[0] = \u201cHassan\u201d ;<\/p>\n\n\n\n<p>user[1] =\u201dIdris\u201d;<\/p>\n\n\n\n<p>&nbsp;user[2]=\u201dTrevor\u201d ;<\/p>\n\n\n\n<p>And their passwords correspond with their indexes.<\/p>\n\n\n\n<p>pass[0] = \u201chomecomingking\u201d;<\/p>\n\n\n\n<p>pass[1] = \u201cturnupcharlie\u201d;<\/p>\n\n\n\n<p>pass[2] = \u201cafraidofthedark\u201d;<\/p>\n\n\n\n<p>Then if one of them had successfully login, the output should be:<\/p>\n\n\n\n<p>Enter username: Hassan<\/p>\n\n\n\n<p>Enter password: homecomingking <\/p>\n\n\n\n<p>Hello Hassan!  <\/p>\n\n\n\n<p>But if not, &#8220;Incorrect Login!&#8221;<\/p>\n\n\n\n<p>You can ignore case for the username but not for the password.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Program Starts: <\/strong> <br>Enter username:<br>Becky<br><br>Enter password: <br>123<br><br><strong>Output: <\/strong><br>Hello Becky!  <br><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 6<\/h2>\n\n\n\n<p>You have to design the code such that the user has only three tries to guess the correct pin of the account. You set the pin as a constant with a final attribute. When correct display &#8220;Correct, welcome back.&#8221; When incorrect display &#8220;Incorrect, try again.&#8221;. When ran out of tries display &#8220;Sorry but you have been locked out.&#8221;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Program Starts: <\/strong> <br>Please enter pin: <br>22132  <br><strong>Output: <\/strong><br>Incorrect, try again.<br>Please enter pin: <br>23412  <br><strong>Output: <\/strong><br>Incorrect, try again.<br>Please enter pin: <br>12345 <br><strong>Output: <\/strong><br>Correct, welcome back.<br><br><strong>Program Starts: <\/strong> <br>Please enter pin: <br>22132  <br><strong>Output: <\/strong><br>Incorrect, try again.<br>Please enter pin: <br>23412  <br><strong>Output: <\/strong><br>Incorrect, try again.<br>Please enter pin: <br>00000 <br><strong>Output: <\/strong><br>Sorry but you have been locked out. <br><br><br><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 7<\/h2>\n\n\n\n<p>Write a program that prompts user for a word and prints &#8220;Yes&#8221; if it is a palindrome and &#8220;No&#8221; if it is not.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Program Starts: <\/strong> <br>Enter a string: <br>mom<br><br><strong>Output: <\/strong><br>Yes <\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 8 (Advanced)<\/h2>\n\n\n\n<p>This is a code wars kata. <a href=\"http:\/\/www.codewars.com\/kata\/57eadb7ecd143f4c9c0000a3\/train\/cpp\">click here<\/a> to train on &#8220;Abbreviate a Two Word Name&#8221; on code wars.<\/p>\n\n\n\n<p>Write a function to convert a name into initials. You can assume the program takes in two words with one space in between them.<\/p>\n\n\n\n<p>The output should be two capital letters with a dot separating them. <\/p>\n\n\n\n<p>It should look like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Program Starts: <\/strong> <br>Please enter name:<br>Sam Smith<br><br><strong>Output: <\/strong><br>S.S<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 9<\/h2>\n\n\n\n<p>This is a code wars kata. <a href=\"http:\/\/www.codewars.com\/kata\/55d24f55d7dd296eb9000030\/train\/cpp\">click here<\/a> to train on &#8220;Grasshopper &#8211; Summation&#8221; on code wars. <\/p>\n\n\n\n<p>Write a program that finds the summation of every number from 1 to num. The number will always be a positive integer greater than 0.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Program Starts: <\/strong> <br>Please enter number<br>2<br><br><strong>Output: <\/strong><br>1 + 2 = 3<br><br><strong>Program Starts: <\/strong> <br>Please enter number<br>8<br><br><strong>Output: <\/strong><br>1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 = 36<br><br><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Exercise 10<\/h2>\n\n\n\n<p>This is a code wars kata. <a href=\"http:\/\/www.codewars.com\/kata\/53dc23c68a0c93699800041d\/train\/javascript\">click here<\/a> to train on &#8220;Sentence Smash&#8221; on code wars. <\/p>\n\n\n\n<p>Write a method <code>smash<\/code>&nbsp;that takes an array of words and smashes them together into a sentence and returns the sentence. You can ignore any need to sanitize words or add punctuation, but you should add spaces between each word.&nbsp;<strong>Be careful, there shouldn&#8217;t be a space at the beginning or the end of the sentence!<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">var words = ['hello', 'world', 'this', 'is', 'great']; smash(words); \/\/ returns \"hello world this is great\"<br><br><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The following java for-loop exercises have been collected from various internet sources such as programmr.com and codewars. Go to my tutoring page if you need more help and would like to talk to a tutor. User input does not work&#8230; <a class=\"more-link\" href=\"https:\/\/avantutor.com\/blog\/10-simple-java-for-loop-exercises-try-it-right-here\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[8,20],"tags":[25,24,23,22],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>10 Simple Java For-Loop Exercises - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding<\/title>\n<meta name=\"description\" content=\"Try any of these basic for-loop exercises to test your Java for-loop skills. Exercises come with their own editor and compiler right here on the page!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/avantutor.com\/blog\/10-simple-java-for-loop-exercises-try-it-right-here\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"10 Simple Java For-Loop Exercises - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding\" \/>\n<meta property=\"og:description\" content=\"Try any of these basic for-loop exercises to test your Java for-loop skills. Exercises come with their own editor and compiler right here on the page!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/avantutor.com\/blog\/10-simple-java-for-loop-exercises-try-it-right-here\/\" \/>\n<meta property=\"og:site_name\" content=\"AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding\" \/>\n<meta property=\"article:published_time\" content=\"2019-03-24T23:06:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-01-28T01:10:13+00:00\" \/>\n<meta name=\"author\" content=\"avansardar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"avansardar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/avantutor.com\/blog\/10-simple-java-for-loop-exercises-try-it-right-here\/\",\"url\":\"https:\/\/avantutor.com\/blog\/10-simple-java-for-loop-exercises-try-it-right-here\/\",\"name\":\"10 Simple Java For-Loop Exercises - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding\",\"isPartOf\":{\"@id\":\"https:\/\/avantutor.com\/blog\/#website\"},\"datePublished\":\"2019-03-24T23:06:58+00:00\",\"dateModified\":\"2020-01-28T01:10:13+00:00\",\"author\":{\"@id\":\"https:\/\/avantutor.com\/blog\/#\/schema\/person\/3a1820bcdd71870ace675436f371be9e\"},\"description\":\"Try any of these basic for-loop exercises to test your Java for-loop skills. Exercises come with their own editor and compiler right here on the page!\",\"breadcrumb\":{\"@id\":\"https:\/\/avantutor.com\/blog\/10-simple-java-for-loop-exercises-try-it-right-here\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/avantutor.com\/blog\/10-simple-java-for-loop-exercises-try-it-right-here\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/avantutor.com\/blog\/10-simple-java-for-loop-exercises-try-it-right-here\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/avantutor.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"10 Simple Java For-Loop Exercises\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/avantutor.com\/blog\/#website\",\"url\":\"https:\/\/avantutor.com\/blog\/\",\"name\":\"AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding\",\"description\":\"Looking for expert advice on how to improve your coding skills? The AvanTutor blog provides a wealth of resources and insights to help you become a better programmer. Our experienced tutors share tips and tricks for mastering popular programming languages such as Java, and JavaScript, as well as insights into the latest trends in software development. With regular updates and engaging content, the AvanTutor blog is your go-to resource for all things coding.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/avantutor.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/avantutor.com\/blog\/#\/schema\/person\/3a1820bcdd71870ace675436f371be9e\",\"name\":\"avansardar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/avantutor.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/81392f2a2c93b7b1c7479ed6b4115f02?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/81392f2a2c93b7b1c7479ed6b4115f02?s=96&d=mm&r=g\",\"caption\":\"avansardar\"},\"url\":\"https:\/\/avantutor.com\/blog\/author\/avansardar\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"10 Simple Java For-Loop Exercises - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","description":"Try any of these basic for-loop exercises to test your Java for-loop skills. Exercises come with their own editor and compiler right here on the page!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/avantutor.com\/blog\/10-simple-java-for-loop-exercises-try-it-right-here\/","og_locale":"en_US","og_type":"article","og_title":"10 Simple Java For-Loop Exercises - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","og_description":"Try any of these basic for-loop exercises to test your Java for-loop skills. Exercises come with their own editor and compiler right here on the page!","og_url":"https:\/\/avantutor.com\/blog\/10-simple-java-for-loop-exercises-try-it-right-here\/","og_site_name":"AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","article_published_time":"2019-03-24T23:06:58+00:00","article_modified_time":"2020-01-28T01:10:13+00:00","author":"avansardar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"avansardar","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/avantutor.com\/blog\/10-simple-java-for-loop-exercises-try-it-right-here\/","url":"https:\/\/avantutor.com\/blog\/10-simple-java-for-loop-exercises-try-it-right-here\/","name":"10 Simple Java For-Loop Exercises - AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","isPartOf":{"@id":"https:\/\/avantutor.com\/blog\/#website"},"datePublished":"2019-03-24T23:06:58+00:00","dateModified":"2020-01-28T01:10:13+00:00","author":{"@id":"https:\/\/avantutor.com\/blog\/#\/schema\/person\/3a1820bcdd71870ace675436f371be9e"},"description":"Try any of these basic for-loop exercises to test your Java for-loop skills. Exercises come with their own editor and compiler right here on the page!","breadcrumb":{"@id":"https:\/\/avantutor.com\/blog\/10-simple-java-for-loop-exercises-try-it-right-here\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/avantutor.com\/blog\/10-simple-java-for-loop-exercises-try-it-right-here\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/avantutor.com\/blog\/10-simple-java-for-loop-exercises-try-it-right-here\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/avantutor.com\/blog\/"},{"@type":"ListItem","position":2,"name":"10 Simple Java For-Loop Exercises"}]},{"@type":"WebSite","@id":"https:\/\/avantutor.com\/blog\/#website","url":"https:\/\/avantutor.com\/blog\/","name":"AvanTutor Blog - Tips, Tricks, and Resources for Mastering Coding","description":"Looking for expert advice on how to improve your coding skills? The AvanTutor blog provides a wealth of resources and insights to help you become a better programmer. Our experienced tutors share tips and tricks for mastering popular programming languages such as Java, and JavaScript, as well as insights into the latest trends in software development. With regular updates and engaging content, the AvanTutor blog is your go-to resource for all things coding.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/avantutor.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/avantutor.com\/blog\/#\/schema\/person\/3a1820bcdd71870ace675436f371be9e","name":"avansardar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/avantutor.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/81392f2a2c93b7b1c7479ed6b4115f02?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/81392f2a2c93b7b1c7479ed6b4115f02?s=96&d=mm&r=g","caption":"avansardar"},"url":"https:\/\/avantutor.com\/blog\/author\/avansardar\/"}]}},"_links":{"self":[{"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/posts\/69"}],"collection":[{"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/comments?post=69"}],"version-history":[{"count":12,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/posts\/69\/revisions"}],"predecessor-version":[{"id":417,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/posts\/69\/revisions\/417"}],"wp:attachment":[{"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/avantutor.com\/blog\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}