9 Replies - 1102 Views - Last Post: 08 July 2010 - 12:26 PM Rate Topic: -----

#1 jp_villanueva  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-August 07

Java code..whats wrong in my code?

Posted 22 August 2007 - 05:17 PM

import java.io.*;
public class Average 
	 {  
	   public static InputStreamReader Reader = new InputStreamReader (System.in);
	   public static BufferedReader input = new BufferedReader(reader);
	   public static void main(String[] args) throws Exception
	   	{   	
		  int Q1,Q2,Q3,Ave;		   		 
				
		System.out.println("Enter First quiz Score");
		Q1=Integer.parseInt (input.readLine());
		System.out.println("Enter Second quiz Score");
		Q2=Integer.parseInt (input.readLine());
		System.out.println("Enter Third quiz Score");
		Q3=Integer.parseInt (input.readLine());
		Ave= Q1+Q2+Q3/3;
		System.out.println("average is   "+Ave);
		}
}

~edit: please next time use code tags.


/*im having an error in my code whenver i try to compile it. i cant find the error in my code..

im a strter in java proggraming language..

and btw what does

public static InputStreamReader Reader = new InputStreamReader (System.in);
public static BufferedReader input = new BufferedReader(reader);
public static void main(String[] args) throws Exception

-->wat does this 3 line of code mean? thx */

This post has been edited by PennyBoki: 22 August 2007 - 05:19 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Java code..whats wrong in my code?

#2 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: Java code..whats wrong in my code?

Posted 22 August 2007 - 05:42 PM

Hi first I'll explain the first 3 lines.

public static InputStreamReader Reader = new InputStreamReader (System.in);
public static BufferedReader input = new BufferedReader(reader);


The first two lines are simply for getting a user's input that's all. Just creating objects that gets the user's input.
Actually in the second line of these 3 line is where the error is appearing, it is in the argument reader which should be Reader, because reader is not defined anywhere and bear in mind that Java is a case-sensitive language which means that reader is not the same with Reader.

The thing is the input which is an object of the BufferedReader class takes an object of the InputStreamReader class as an argument, in our case Reader. But I believe that it's more confusing than explanatory, so if you are beginner take them as they are, or try to google those classes to see their features.

you can do those two lines in one like this:
BufferedReader input = new BufferedReader(new InputStreamReader (System.in));
use them any way you want.

As for the last one of the three lines, it's the main function, and you'll use it many many times, learn it as it is.


But I do have remarks on the code's logic. I guess you want to find average but Ave is an integer, and the formula by which you calculate the average is a bit strange.
Was This Post Helpful? 0
  • +
  • -

#3 B@LL!ST!C  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 152
  • Joined: 20-August 07

Re: Java code..whats wrong in my code?

Posted 22 August 2007 - 11:32 PM

try checking your codes. i can see error on your codes. java is very case sensitive. 1 wrong character and your program will not work.

and there's something wrong in calculating your Average like Penny said

try running it and look what the errors said

This post has been edited by B@LL!ST!C: 22 August 2007 - 11:52 PM

Was This Post Helpful? 0
  • +
  • -

#4 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: Java code..whats wrong in my code?

Posted 23 August 2007 - 03:31 AM

View PostB@LL!ST!C, on 22 Aug, 2007 - 11:32 PM, said:

java is very case sensitive


haha that was funny
Was This Post Helpful? 0
  • +
  • -

#5 B@LL!ST!C  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 152
  • Joined: 20-August 07

Re: Java code..whats wrong in my code?

Posted 23 August 2007 - 05:25 PM

View PostPennyBoki, on 23 Aug, 2007 - 03:31 AM, said:

View PostB@LL!ST!C, on 22 Aug, 2007 - 11:32 PM, said:

java is very case sensitive


haha that was funny


what's with that??? :huh: :P
Was This Post Helpful? 0
  • +
  • -

#6 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: Java code..whats wrong in my code?

Posted 23 August 2007 - 06:12 PM

View PostB@LL!ST!C, on 23 Aug, 2007 - 05:25 PM, said:

View PostPennyBoki, on 23 Aug, 2007 - 03:31 AM, said:

View PostB@LL!ST!C, on 22 Aug, 2007 - 11:32 PM, said:

java is very case sensitive


haha that was funny


what's with that??? :huh: :P

the use of the word very :)
Was This Post Helpful? 0
  • +
  • -

#7 B@LL!ST!C  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 152
  • Joined: 20-August 07

Re: Java code..whats wrong in my code?

Posted 23 August 2007 - 06:15 PM

heheheheheh :D
to much exageration :P
just kidding...
Was This Post Helpful? 0
  • +
  • -

#8 jp_villanueva  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-August 07

Re: Java code..whats wrong in my code?

Posted 27 August 2007 - 04:18 AM

thanx .. =) sir ballistic and Pennyboki

This post has been edited by jp_villanueva: 27 August 2007 - 04:21 AM

Was This Post Helpful? 0
  • +
  • -

#9 Guest_freshmen*


Reputation:

Re: Java code..whats wrong in my code?

Posted 08 July 2010 - 12:22 PM

Unreadable code removed
Anyhow necroposted post

This post has been edited by pbl: 08 July 2010 - 05:28 PM

Was This Post Helpful? 0

#10 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 9143
  • View blog
  • Posts: 33,935
  • Joined: 27-December 08

Re: Java code..whats wrong in my code?

Posted 08 July 2010 - 12:26 PM

@freshman: Please stop necroposting. Also, please respect rule #2 of this forum. While we're not asking for poetry, you need to speak in comprehensible English, as this is an English speaking forum.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1