StringMath - System.out.print("Please enter...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// File: InputString.java // Course: CSC 211 // Author: Greg Ware // Date: January 31, 2011 // Purpose: Module 3 Program / import java.util.*; i public class StringMath { public static void main(String[] args) { int quiz1 = 0, quiz2 = 0, quiz3 = 0; double avg = 0.0; Scanner in = new Scanner(System.in); S // Enter three integers with one prompt System.out.print("Please enter three quiz scores: "); quiz1 = in.nextInt(); quiz2 = in.nextInt(); quiz3 = in.nextInt(); q // Make the numbers positive using Math.abs quiz1 = Math.abs(quiz1); quiz2 = Math.abs(quiz2); quiz3 = Math.abs(quiz3); q // Compute the average quiz score / avg = (quiz1 + quiz2 + quiz3)/3.0; a in.useDelimiter(System.getProperty("line.separator")); i // Enter a quote with spaces
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: System.out.print("Please enter your favorite quote: "); String quote = in.next(); S // Find the first word in the quote int index = quote.indexOf(" "); //System.out.println("index = " + index); index = Math.max(0, index); // If index > 0, then index won't change in the statement above // If index == -1, then index will become 0 String firstWord = quote.substring(0,index); S System.out.println("The three quiz scores are: " + quiz1 + ", " + quiz2 + ", " + quiz3); System.out.printf("The average quiz score is: %.1f%n", avg); S System.out.println("The quote is: " + quote); S System.out.println("The first word in the quote is: " + firstWord); S } }...
View Full Document

Ask a homework question - tutors are online