rei Posted April 29, 2008 Report Posted April 29, 2008 hello i need help in java programming :X the quesiton i am doing require the answer to show Example 1 Enter one of five integers to average:5 Enter one of five integers to average:5 Enter one of five integers to average:5 Enter one of five integers to average:5 Enter one of five integers to average:5 The average of the five integers is 5 (notice the spacing between each line) but when i do my java it shows Example 2 Enter one of five integers to average:5 Enter one of five integers to average:5 Enter one of five integers to average:5 Enter one of five integers to average:5 Enter one of five integers to average:5 The average of the five integers is 5 here is my java codes import java.util.Scanner; public class AverageOf5Nos { public static void main (String arg[]) { int first, second, third, fourth, fifth, average; Scanner entry = new Scanner ( System.in ); System.out.print("Enter one of five integers to average:" ); first = entry.nextInt() ; System.out.print("Enter one of five integers to average:" ); second = entry.nextInt() ; System.out.print("Enter one of five integers to average:" ); third = entry.nextInt() ; System.out.print("Enter one of five integers to average:" ); fourth = entry.nextInt() ; System.out.print("Enter one of five integers to average:"); fifth = entry.nextInt() ; average =( first + second + third + fourth + fifth ) /5; System.out.print("The average of the five integers is " + average); }//main() }//class how do i make the spacing between each " Enter one of fice integers to average" like in example 1
rei Posted April 29, 2008 Author Report Posted April 29, 2008 do u mind pasting out the whole code coz i am still new in java :X
Phantom Assasin Posted April 29, 2008 Report Posted April 29, 2008 lolx i dont even know java, i know javascript :P i just thought it's the same hehe, coz i use to edit my friendster using javascript to obtain full styling
Sensation Posted April 29, 2008 Report Posted April 29, 2008 \n infront of each line inside the system.out.printline("") e.g. System.out.println("\nEnter one of five integers to average:")
rei Posted April 30, 2008 Author Report Posted April 30, 2008 new problem!! D: import javax.swing.JOptionPane; public class TempConversion{ public static void main (String args [] ) { String input, fahrenheight, welcomeMessage, temperature, outputMessage; welcomeMessage = "Welcome to the temperature conversion program."; fahrenheight = JOptionPane.showInputDialog( welcomeMessage + "Enter the temperature in Fahrenheight degrees to the nearest degree. "); input = Integer.parseInt ( fahrenheight ); temperature = (input - 32) * 5/9; outputMessage = "The Fahrenheit temperature of" + input + "equals a Celsius temperature of + temperature"; JOptionPane.showMessageDialog( null, outputMessage ) ; System.exit(0); }//main }//class i cant find ou what went wrong argh :X its suppose to show a popup saying Welcome to the temperature conversion program. Enter the temperature in Fahrenheight degrees to the nearest degree. (a box for u to type ur input on degrees) when u typed it out E.G 64 fahrenheight degrees another pop up shows The Fahrenheit temperature of 64 equals a Celsius temperature of 17.8
rei Posted April 30, 2008 Author Report Posted April 30, 2008 errors for above post TempConversion.java:11: incompatible types found : int required: java.lang.String input = Integer.parseInt ( fahrenheight ); ^ TempConversion.java:13: operator - cannot be applied to java.lang.String,int temperature = (input -32) * 5/9; ^ TempConversion.java:13: incompatible types found : int required: java.lang.String temperature = (input -32) * 5/9; ^
rei Posted April 30, 2008 Author Report Posted April 30, 2008 temperature = (input - 32) * 5/9; TempConversion.java:14: incompatible types found : int required: java.lang.String temperature = (input - 32) * 5/9; i duno wad kind of error this is o.O