CS Homework + Scanner + Buffer

Labels: ,
Supposedly, you're to ask the user for the Array size and the Elements.

And output the following:
1 - Minimum Value
2 - Maximum Value
3 - Mean / Average Value

For bonus points:
4 - Median
5 - Mode

SCANNER

import java.util.Scanner;

public class InputByScanner {

public static void main(String[] args) {

String name;
int age;
Scanner in = new Scanner(System.in);

System.out.print("Input Name: ");
name = in.nextLine();
System.out.print("Input Age: ");
age =in.nextInt();

in.close();

// Prints name and age to the console
System.out.println("Name :"+name);
System.out.println("Age :"+age);

}
}


BUFFER

import java.io.*;


public class InputByBufferReader {

public static void main(String args[]) throws IOException {
String s = "";

InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(isr);

do{

System.out.print("Input: ");

s = in.readLine();

System.out.println("You typed: " + s);
}while(!s.equalsIgnoreCase("exit"));

in.close();
}
}
0 comments:

Post a Comment

Hi. :-h


Chem2

Recent Entries

Recent Comments