Use Java (array) to create a program that allows users to enter
their name (followed by a comma) and top three scores (separated by
spaces) on the same line. If the third score is larger than the
first score, the program should output name got better! Otherwise,
it should output name did not get better!
Sample Run:
Enter your name and top 3 scores:
Jon Doe,40 40 50
Jon Doe got better!
Sample Run:
Enter your name and top 3 scores:
jon doe,40 40 30
jon doe didn't get better!
import java.util.Scanner; public class Scores3 { public static void main(String[] args) { String s; Scanner scnr = new Scanner(System.in); System.out.println("Enter your name and top 3 scores:"); s = scnr.nextLine(); String[] splits = s.split(","); String name = splits[0]; String scores[] = splits[1].split(" "); if(Integer.parseInt(scores[0]) < Integer.parseInt(scores[2])){ System.out.println(name+" got better"); } else{ System.out.println(name+" didn't got better"); } } }
Get Answers For Free
Most questions answered within 1 hours.