Question
Can someone please run this through Java and make sure I have done this correctly? I can't get #10 to return as a string but
Can someone please run this through Java and make sure I have done this correctly? I can't get #10 to return as a string but I would rather the code run without errors or at least be correct unless you can fix it. I will rate any helpful answers or answers with corrections to my code!
6.Write (define) a static method named averageLength, that takes three String arguments. When this function is called, it should return the average length (number of characters) of the String arguments passed to it as a double 7.Write (define) a static method named lengthOfShortest, that takes two String arguments. When this function is called, it should return the length (number of characters) of the shortest String argument passed to it as an int.
8.Write (define) a static method named stringOfStars, that takes one String argument. When this function is called, it should return a String of asterisks (*) that is the same length as the string argument passed to it
import java.util.*;
public class Assignment05 { public static void main(String[] args) { System.out.println("Dylan Zurfluh Assignment 5"); }
//6) Write (define) a static method named averageLength public static double averageLength(String a, String b, String c) { int len_a, len_b, len_c; double averageLen; //Intake your 3 String values Scanner scan = new Scanner(System.in); System.out.println("Please enter your three inputs for your average length calculation."); System.out.println("Value 1: "); a = scan.next(); System.out.println("Value 2: "); b = scan.next(); System.out.println("Value 3: "); c = scan.next(); //calculate lengths of strings a,b,c len_a = a.length(); len_b = b.length(); len_c = c.length(); averageLen = (len_a+len_b+len_c)/3; return averageLen; } //7) Write (define) a static method named lengthOfShortest public static int lengthOfShortest(String a, String b) { int len_a; int len_b; Scanner scan = new Scanner(System.in); System.out.println("Please enter your two inputs for your average length calculation."); System.out.println("Value 1: "); a = scan.next(); System.out.println("Value 2: "); b = scan.next(); //find lengths of strings len_a = a.length(); len_b = b.length(); //set up if else to direct flow if(len_a < len_b) { return len_a; } else { return len_b; } } //8) Write a static method named stringOfStars public static String stringOfStars(String str) { Scanner scan = new Scanner(System.in); System.out.println("Please enter your input you would like to encrypt with stars."); str = scan.next(); String string=""; for(int i=0;i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started