CSC 1301 Lab #10 PART 2. · Please explain the following examples related to how to pass any parameter into the methods. Example 1: 1 public class Triangles { 2 public static void main(String[] args) {...

1 answer below »
Please provide code and final output. Please follow all instructions.Can I expertsudipta. To complete my assignment


CSC 1301 Lab #10 PART 2. · Please explain the following examples related to how to pass any parameter into the methods. Example 1: 1 public class Triangles { 2 public static void main(String[] args) { 3 System.out.println("hypotenuse 1 = " + hypotenuse(5, 12)); 4 System.out.println("hypotenuse 2 = " + hypotenuse(3, 4)); 5 } 6 7 public static double hypotenuse(double a, double b) { 8 double c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)); 9 return c; 10 } 11 } Output: hypotenuse 1 = 13.0 hypotenuse 2 = 5.0 Example 2: String s1 = "hello"; for (int i = 0; i < s1.length();="" i++)="" {="" system.out.println(i="" +="" ":="" "="" +="" s1.charat(i));="" }="" output:="" 0:="" h="" 1:="" e="" 2:="" l="" 3:="" l="" 4:="" o="" example="" 3:="" string="" s1="hello" ;="" for="" (int="" i="0;" i="">< s1.length(); i++) { system.out.print(i + ": " + s1.charat(i)+"\t"); system.out.println(s1.substring(i+1, s1.length())); } output: 0: hello 1: ello 2: llo 3: lo 4: o question 4: write a program 1. enter a string value as a variable “word”: “instructorcanofferminimalhints” 2. create a method that is called “showpairs(string word)” · in the method, the program shows us “word” that is separated by 2 characters output: enter whole word: instructorcanofferminimalhints in st ru ct or ca no ff er mi ni ma lh in ts question 5: write a program 1. enter a string value as a variable “word”: “instructorcanofferminimalhints” 2. create a method that is called “showpairs(string word)” · in the method, the program shows us “word” that is separated by 3 characters output: enter whole word: instructorcanofferminimalhints ins tru cto rca nof fer min ima lhi nts question 6: write a program 1. enter a string value as a variable “word”: “instructorcanofferminimalhints” 2. create a method that is called “showpairs(string word)” · in the method, the program shows us “word” that is separated by 4 characters (you do not need to consider last two characters output: enter whole word: instructorcanofferminimalhints inst ruct orca noff ermi nima lhin page 2 of 10 s1.length();="" i++)="" {="" system.out.print(i="" +="" ":="" "="" +="" s1.charat(i)+"\t");="" system.out.println(s1.substring(i+1,="" s1.length()));="" }="" output:="" 0:="" h="" ello="" 1:="" e="" llo="" 2:="" l="" lo="" 3:="" l="" o="" 4:="" o="" question="" 4:="" write="" a="" program="" 1.="" enter="" a="" string="" value="" as="" a="" variable="" “word”:="" “instructorcanofferminimalhints”="" 2.="" create="" a="" method="" that="" is="" called="" “showpairs(string="" word)”="" ·="" in="" the="" method,="" the="" program="" shows="" us="" “word”="" that="" is="" separated="" by="" 2="" characters="" output:="" enter="" whole="" word:="" instructorcanofferminimalhints="" in="" st="" ru="" ct="" or="" ca="" no="" ff="" er="" mi="" ni="" ma="" lh="" in="" ts="" question="" 5:="" write="" a="" program="" 1.="" enter="" a="" string="" value="" as="" a="" variable="" “word”:="" “instructorcanofferminimalhints”="" 2.="" create="" a="" method="" that="" is="" called="" “showpairs(string="" word)”="" ·="" in="" the="" method,="" the="" program="" shows="" us="" “word”="" that="" is="" separated="" by="" 3="" characters="" output:="" enter="" whole="" word:="" instructorcanofferminimalhints="" ins="" tru="" cto="" rca="" nof="" fer="" min="" ima="" lhi="" nts="" question="" 6:="" write="" a="" program="" 1.="" enter="" a="" string="" value="" as="" a="" variable="" “word”:="" “instructorcanofferminimalhints”="" 2.="" create="" a="" method="" that="" is="" called="" “showpairs(string="" word)”="" ·="" in="" the="" method,="" the="" program="" shows="" us="" “word”="" that="" is="" separated="" by="" 4="" characters="" (you="" do="" not="" need="" to="" consider="" last="" two="" characters="" output:="" enter="" whole="" word:="" instructorcanofferminimalhints="" inst="" ruct="" orca="" noff="" ermi="" nima="" lhin="" page="" 2="" of="">
Answered Same DayMar 26, 2021

Answer To: CSC 1301 Lab #10 PART 2. · Please explain the following examples related to how to pass any...

Rushendra answered on Mar 27 2021
154 Votes
Solutions/~$b-10-solutions.docx
Solutions/code/ShowPairsFour.java
Solutions/code/ShowPairsFour.java
import java.util.*;
public class ShowPairsFour {
    public static void main(String[]
 args) {
        System.out.println("Enter the word");
        Scanner s=new Scanner(System.in);
        String word=s.nextLine();
        showPairs(word);
     }

     public static void showPairs(String word) {

        for(int i=0;;i+=4){
             if(i>=word.length()){
                 break;
             }
             if(i==word.length()-3){
                //System.out.println(word.charAt(i)+""+word.charAt(i+1)+""+word.charAt(i+2));
                break;
            }
             if(i==word.length()-2){
                //System.out.println(word.charAt(i)+""+word.charAt(i+1));
                break;
            }
             if(i==word.length()-1){
                 //System.out.println(word.charAt(i));
                 break;
             }
             System.out.println(word.charAt(i)+""+word.charAt(i+1)+""+word.charAt(i+2)+""+word.charAt(i+3));
         }

     }
}
Solutions/code/ShowPairsThree.java
Solutions/code/ShowPairsThree.java
import java.util.*;
public class ShowPairsThree {
        public static void main(String[] args) {
        System.out.println("Enter the word");
        Scanner s=new Scanner(System.in);
        String word=s.nextLine();
        showPairs(word);
     }

     public static void showPairs(String word) {

        for(int i=0;;i+=3){
             if(i>=word.length()){
                 break;
             }
             if(i==word.length()-2){
                System.out.println(word.charAt(i)+""+word.charAt(i+1));
                break;
            }
             if(i==word.length()-1){
                 System.out.println(word.charAt(i));
                 brea...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here