Eliminate the last comma in the string output

Assignment Help JAVA Programming
Reference no: EM13860520

Eliminate the last comma in the String Output which includes array output values from "hourlyTemp[i]" (entire list). My guess is that this needs to incorporate "%d" somehow but my online book won't accept the use of "%d" for some reason. From the book: Quoted Question: "Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate elements with a comma and space. Ex: If hourlyTemp = {90, 92, 94, 95}, print:

90, 92, 94, 95

Note that the last element is not followed by a comma, space, or newline."

import java.util.Scanner;

public class PrintWithComma {

public static void main (String [] args) {

final int NUM_VALS = 4;

int[] hourlyTemp = new int[NUM_VALS];

int i = 0;

hourlyTemp[0] = 90;

hourlyTemp[1] = 92;

hourlyTemp[2] = 94;

hourlyTemp[3] = 95;

for (i = 0; i System.out.print(hourlyTemp[i] + ", ");

}

System.out.println("");

return;

}

}

Reference no: EM13860520

Provide a mechanism for repeating a block of code

CPS 150- Loops provide a mechanism for repeating a block of code called the loop body. We begin this lab by experimenting with while loops, the simplest form of loop code.

Determine whether a given credit card number is valid or not

Implement Luhn's algorithm in a program to determine whether a given credit card number is valid or not. You must test if the number of digits in the input is in the valid r

Creating an application that accepts product data

You have been tasked with creating an application that accepts product data and displays this information. The application also computes average sales and shipping charges

Collection of scores (type int) for the last exam i

After being given a collection of scores (type int) for the last exam in your computer course, you are to computer the average of the scores and assign grades (O, S, U i.e. Ou

Function searches all files specified on the command line

Write a program Find that searches all files specified on the command line and prints out all lines containing a reserved word. For example, if you call java Find ring repor

Balanced and competitive business practices

The United States has several laws that are intended to further fair, balanced, and competitive business practices. Do you think that such laws are effective? If so, why? If n

Describe a good application of a linked list data structure

Describe a good application of a linked list data structure. What are some issues that should be taken into account when considering using a linked list versus another data st

Write a program that plays the memory matching game

Create a class HugeInteger which uses a 40-element array of digits to store integers as large as 40 digits each - output a large number of newlines to force the old board.

Reviews

Write a Review

 
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd