Jump to content
rei

need help with java :X

Recommended Posts

Posted

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

Posted

\n infront of each line inside the system.out.printline("")

e.g.

System.out.println("\nEnter one of five integers to average:")

Posted

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

Posted

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;

^

Posted

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



×
×
  • Create New...