Featured Contents

X and Y axis Program

Problem: Write a program that prompts the user to input the x-y coordinate of a point in a Cartesian plane. The program should then output a message indicating whether the point is the origin point, is located on the x or y axis or appears on a particular quadrant.

Cellphone Bill Computation

Problem: Write a program that calculates and prints the bill for a cellular telephone company. The company offers two types of service: regular and premium. Its rates vary depending on the type of service. The rates are computed as follows:

Latest Posts

0

Fibonacci Java Program

BufferedReader

Output:

Source Code:

import java.io.*;
public class Fibonacci {
private static PrintStream p=System.out;
public static BufferedReader q=new BufferedReader (new InputStreamReader (System.in));
public static void main(String []args)throws IOException{

String ans;
do{
p.print("Enter Limit: ");
int n=Integer.parseInt(q.readLine());

int x=1, y=1, z;
p.print(x +" "+y +" ");

for (int i=0; i

z=y+x;
if (z<=n){
p.print(z +" ");
x=y;
y=z;
}
}
p.println();
p.println("Try again?[y/n]: ");
ans=q.readLine();
}
while(ans.charAt(0)=='Y' || ans.charAt(0)=='y');
}
}
0

Java Program: Simple Multiplication Table

BufferedReader

Machine Problem:
Create a Multiplication Table that ranges from 2 to 12 only.

Output:

Source Code:

import java.io.*;
public class MultiplicationTable {
private static PrintStream p=System.out;
public static BufferedReader q= new BufferedReader (new InputStreamReader (System.in));
public static void main(String []args)throws IOException{
int n,x,y,z;
p.println("MULTIPLICATION TABLE");
do{
p.print("Enter a number (2-12): ");
String num=q.readLine();
n=Integer.parseInt(num);
}
while(n<=1||n>=13);

for (x=1; x<=n; x++){
for (y=1; y<=n; y++){
z=x*y;
p.print(z +" ");
}
p.println();
}
}
}
0

Simple Addition, Division, and Do While in Java

BufferedReader , ,


Create a Program that will add or divide, then ask the user if they'd want to perform the computation again using Do While

Output:

Source Code:

import java.io.*;
public class AddDivide {
private static PrintStream p=System.out;
public static BufferedReader q=new BufferedReader(new InputStreamReader (System.in));
public static void main (String []args)throws IOException{

p.println("MAIN MENU");
p.println();
p.println("[A] Addition");
p.println("[D] Division");
p.println("[E] Exit");
p.println();



p.print("Input Operation: ");
String input=q.readLine();
String o;


if (input.equals("A")|| input.equals("a"))
{
do{
p.print("Enter First Number: ");
String num1=q.readLine();
double n1=Double.parseDouble(num1);

p.print("Enter Second Number: ");
String num2=q.readLine();
double n2=Double.parseDouble(num2);

double sum;
sum=n1+n2;

p.println("The SUM is: " +sum);

p.println("Perform Addition again? [Y/N] ");
o=q.readLine();
}
while(o.equals("Y") || o.equals("y"));
}
else if (input.equals("D") || input.equals("d"))
{
do{
p.print("Enter First Number: ");
String num1=q.readLine();
double n1=Double.parseDouble(num1);

p.print("Enter Second Number: ");
String num2=q.readLine();
double n2=Double.parseDouble(num2);

double quo;
quo=n1/n2;

p.println("The quotient is: " +quo);

p.println("Perform Division again? [Y/N] ");
o=q.readLine();
}
while(o.equals("Y") || o.equals("y"));
}
else if (input.equals("E") || input.equals("e"))
{
System.exit(0);
}
else
{
p.print("Invalid Input!");
}

}

}
0

Char Sorting: Ascending and Descending in Java

BufferedReader ,

Create a java program that will sort the characters in ascending and descending order

Output:


Source Code:

import java.io.*;
import java.util.*;
public class charSorting
{
private static PrintStream pp=System.out;
public static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public static void main(String args[])throws IOException
{
char[] a=new char[5];
int x,y;

for (x=0;x1)
{
pp.println("You Entered a String!");
x=x-1;continue;
}
else
a[x]=b.charAt(0);
}
pp.println();
pp.print("Given Letter:");
for (y=0;y=0;y--)
pp.print(a[y]+" ");

}
}

0

Multiples of a Number

BufferedReader

Problem:
Write a program that will output the multiples of a number. Arrange it from lowest to highest.

Sample Output:


Source Codes:

package javaapplication1;

import java.io.*;
public class Multiple {

public static BufferedReader q= new BufferedReader(new InputStreamReader (System.in));
public static void main(String []args)throws IOException{

System.out.print("Enter a Number: ");
String a=q.readLine();
int b=Integer.parseInt(a);

for (int x=1; x int y;
y=b%x;
if (y==0)
{
System.out.println(x);
}
}
}
0

Reversed Numbers in Java

BufferedReader
Sample Output:

package javaapplication1;

public class ReservedNumbers {

public static void main(String[] args) {

int n = 12345;

int t,r = 0;

System.out.println("The original numbers : " + n);

do

{

t = n % 10;

r = r * 10 + t;

n = n / 10;

}

while (n > 0);

System.out.println("The reversed numbers : " + r);

}

}

0

How to Open Edit Window for Programming

BufferedReader

How to open an edit Window:

Note: Make sure you have a Java bin.

Go to command prompt and encode the following:

1. cd\
2. cd Program Files
3. cd java
4. dir
Look for the jdk as shown above then follow the next step
5. cd jdk1.6.0_22
6. cd bin
7. edit filename.java

You'd be directed to edit window.

How to run
1. Alt F-S
2. Alt F-X
3. javac filename.java
4. java filename

How to edit
1. edit filename.java

as discussed in AMA East Rizal Campus, Philippines


0

Java Program: X and Y axis

BufferedReader


Problem:
Write a program that prompts the user to input the x-y coordinate of a point in a Cartesian plane. The program should then output a message indicating whether the point is the origin point, is located on the x or y axis or appears on a particular quadrant.

Sample Output:










package javaapplication1;
import java.io.*;

public class N8 {
public static BufferedReader q=new BufferedReader (new InputStreamReader (System.in));
public static void main (String []args)throws IOException{

System.out.print("Input x: ");
String X=q.readLine();
int x=Integer.parseInt(X);

System.out.print("Input y: ");
String Y=q.readLine();
int y=Integer.parseInt(Y);

if (x>0 && y>0)
{
System.out.print("Quadrant 1");
}
else if (x<0 && y>0)
{
System.out.print("Quadrant 2");
}
else if (x<0 && y<0) { System.out.print("Quadrant 3"); } else if (x>0 && y<0) { System.out.print("Quadrant 4"); } else if (x==0 && y<0) { System.out.print("Y axis"); } else if (x==0 && y<0 && y>0)
{
System.out.print("Y axis");
}
else if (x<0 && y==0) { System.out.print("X axis"); } else if (x>0 && y==0)
{
System.out.print("X axis");
}
else
{
System.out.print("Origin");
}
}
}


1

Simple Calculator using Buffered Reader

BufferedReader


Problem:
Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It should then output the number, the operator and the result. (For division, if the denominator is 0, output an appropriate message.)

Sample Output:








import java.io.*;

public class n6 {
public static BufferedReader q=new BufferedReader (new InputStreamReader (System.in));
public static void main (String []args)throws IOException{

System.out.print("Enter 1st number: ");
String num1=q.readLine();
int n1=Integer.parseInt(num1);

System.out.print("Enter operation: ");
String op=q.readLine();
char o=op.charAt(0);

System.out.print("Enter 2nd number: ");
String num2=q.readLine();
int n2=Integer.parseInt(num2);

if (n2==0 && o=='/')
{
System.out.println("Error");
}

else if(o == '+')
{
int sum=0;
sum=n1+n2;

System.out.println("The sum is " +sum);
}
else if(o == '-')
{
int diff=0;
diff=n1-n2;

System.out.println("The difference is " +diff);
}
else if(o == '*')
{
int prod=0;
prod=n1*n2;

System.out.println("The product is " +prod);
}
else if(o == '/')
{
double quo=0;
quo=n1/n2;

System.out.println("The quotient is " +quo);
}
else
{

System.out.println("Invalid");
}

}
}


0

Numbers to words in Java

BufferedReader
Buffered Reader
Problem:

Write a program that accepts a number and output its equivalent in words.

Sample input/output:

Codes:

package javaapplication1;

import java.io.*;

public class num1 {

public static int charAt(int num, int index) {

return String.valueOf(num).charAt(index); }

private static PrintStream sys = System.out;

public static BufferedReader q = new BufferedReader (new InputStreamReader(System.in));

public static void main(String[] args) throws IOException {

String[] units = {null, "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

String[] tenths = {"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen",

"seventeen", "eighteen", "nineteen"};

String[] special = {null, null, "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"};

String[] hundreds = {null, "one hundred", "two hundred", "three hundred", "four hundred", "five hundred",

"six hundred ", "seven hundred", "eight hundred", "nine hundred"};

String[] thousands = {null, "one thousand", "two thousand", "three thousand", "four thousand",

"five thousand","six thousand", "seven thousand", "eight thousand", "nine thousand"};

int y = 0, num = 0;

do {

sys.print("Enter a number: "); num = Integer.parseInt(q.readLine());

if (num < 10000)

y = 1;

} while (y==0);

int x = Integer.toString(num).length();

switch (x)

{

case 1: {

if (num == 0)

sys.println("zero");

else

sys.println(units[num]);

break; }

case 2: {

if (charAt(num,0) - '0' == 1)

sys.println(tenths[charAt(num,1) - '0']);

else

{

sys.print(special[charAt(num,0) - '0']+" ");

sys.println(units[charAt(num,1) - '0']);

}

break; }

case 3: {

sys.print(hundreds[charAt(num,0) - '0']+" ");

{

if (charAt(num,1) - '0' == 1)

sys.print(tenths[charAt(num, 2) - '0']);

else if (charAt(num,1) - '0' == 0)

{ if (charAt(num, 2) - '0' != 0)

sys.print(units[charAt(num, 2) - '0']); }

else

{

sys.print(special[charAt(num, 1) - '0'] + " ");

if (charAt(num,2) - '0' != 0)

sys.print(units[charAt(num,2) - '0']);

}

}

sys.println();

break; }

case 4: {

sys.print(thousands[charAt(num,0) - '0']+" ");

if (charAt(num,1) - '0' != 0)

sys.print(hundreds[charAt(num,1) - '0']+" ");

{

if (charAt(num,2) - '0' == 1)

sys.print(tenths[charAt(num, 3) - '0']);

else if (charAt(num,2) - '0' == 0)

{ if (charAt(num, 3) - '0' != 0)

sys.print(units[charAt(num, 3) - '0']); }

else

{

sys.print(special[charAt(num, 2) - '0'] + " ");

if (charAt(num,3) - '0' != 0)

sys.print(units[charAt(num,3) - '0']);

}

}

sys.println();

break; }

}

}

}


 
Copyright 2010 BufferedReader