my programs with difficulty are below:
Program 20: Alphabet.java
Write a program that will receive 3 words, print out the word that comes last alphabetically despite whether it is uppercase or lowercase. Do this 3 times.
I put: Please tell me my error.
import java.lang.String; import java.util.Scanner; public class Alphabet { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.println("Please enter a word"); String wordone=input.next(); System.out.println("Please enter another word"); String wordtwo=input.next(); System.out.println("Please enter a third word"); String wordthree=input.next(); String wordfour=wordone.compareTo(wordtwo); String wordfive=wordtwo.compareTo(wordthree); String wordsix=wordone.compareTo(wordthree); System.out.println (wordfour); System.out.println (wordfive); System.out.println (wordsix); } }
Program 21: Middle.java
Write a program that will receive a person’s full name in one String object (don’t read in 3 names). Then receive a second person’s full name. Print out whether the 2 people have the same middle name or not. Do this 3 times.
I am unable to understand how to print out only the middle name.
I put:
import java.util.Scanner; public class Middle { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.println("Please enter your first name"); String firstone=input.next(); System.out.println("Please enter your middle name"); String middleone=input.next(); System.out.println ("Please enter your last name"); String lastone=input.next(); for(int i=0;i<length;i++) { System.out.println(middleone); } } }
Program 22: WeCanWorkItOut.java
Write a program that will receive 5 numbers and print out the largest number and the smallest number. Print the average.
import java.util.Scanner; import java.util.Random; public class GuessWhat { public static void main (String[] args) { GuessWhat example= new GuessWhat(); example.getRandomNumber(); } public void getRandomNumber() { int min=50; int max=100; Random randGenerator= new Random(); int randomNum=randGenerator.nextInt(max-min+1)+ min; System.out.println("Random number generated is:" + randomNum); } }
PLEASE HELP ME WITH OTHER PROGRAMS ALSO BECAUSE MY DEADLINE IS TOMORROW.
Sincerely,
ian