megabajt (12-10-2012)
Code:import java.io.*; class Conversation { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int myAge = 15; System.out.println("What is your name?"); String name = in.readLine(); System.out.println("Your name is " + name + ", great name."); System.out.println("How old are you?"); String age = in.readLine(); System.out.println("You are " +age+"."); System.out.print("If you added our ages together we would be" + (age + myAge) + " :)"); System.out.println("What is your favorite hobbie?"); String hobby = in.readLine(); System.out.println("What do you like about " + hobby+"?"); String otherHobby = in.readLine(); System.out.println("So what you're saying about " + otherHobby + " is neat."); System.out.println("Well it was nice talking to you"); System.out.println("Please rate this program 1 - 10"); System.out.println("Type a number:"); String rating = in.readLine(); int value = Integer.parseInt(rating); if (value > 5) { System.out.println("You voted: "+value+"."); } else { System.out.println("You voted: "+value+"."); } System.out.println("End of program"); } }
megabajt (12-10-2012)
Bro, this is good can you expain what this mean?
throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
When you throw an exception, it means that the handling of a runtime error is passed off to the caller of the function which sent it, and no UI message or other such annoyance occurs. A BufferedReader is a class which is used to read a string of characters in from the console byte by byte and parse them into a String.
You seem to be around the same skill level as me, and if you are - hello!
Anyway, couldn't Scanner(in the java.util library) achieve the same thing as BufferedReader? I find Scanner more reliable than BufferedReader, as you don't have to parse into integers and that sort of stuff...
>.< i did this program as pratice for my java class last week lol...didnt know it was here heheheheh
I find the scanner class a lot more convenient, and that's probably because I use it more often than the clunky Buffer class.
As much as I love buffered reader, scanner does a whole lot of job for me . Also now you might wanna grab in the output you give from a text file and manipulate using Arrays to make it more advanced
Doing more Java and Python
Need help with your hack? Ask me, I will try to help you with all my might .
This code is really sloppy, or at least looks like it from thr mobile version. Space everything out.