Search the web
Custom Search


Price: Rs.225 Buy from Flipkart.com

Java Language is a new approach for the school students. The matter has been explained in simple language. Programs are user friendly.Each chapter contains a number of solved examples, a set of objectives and short questions followed by long questions.

Author - Vijay Kumar Pandey
---------------------------------------------------------------------------------------------
List Price: Rs.300 Price: Rs.288 Buy from Flipkart.com

This book is for beginning programmers studying the java language. The book teaches object oriented principles, using the BlueJ development environment.
------------------------------------------------------------------------------------------------------------------------------------------------------------
Price: Rs.280 Buy from Flipkart.com

Author - Vijay Kumar Pandey & Dilip Kumar Dey
------------------------------------------------------------------------------------------------------------------------------------------------------------

Flipkart Deal of the Day




Program Based On Inbuilt Function

WAP to enter the marks of ten subjects. Find the average marks and truncated value of average.

Program :

import java.io.*;
public class inbuilt5
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);

double marks[] = new double[10];
double total=0;
double avg=0;
double round=0;

for(int i=0;i<10;i++) p="i+1;" j="0;j<10;j++)" total="total+marks[j];" avg =" total/10;" round =" Math.rint(avg);" is = "+avg); System.out.println(" is =" ">Program Execution:

Enter the marks of 1 subject
90
Enter the marks of 2 subject
92
Enter the marks of 3 subject
94
Enter the marks of 4 subject
84
Enter the marks of 5 subject
86
Enter the marks of 6 subject
91
Enter the marks of 7 subject
81
Enter the marks of 8 subject
83
Enter the marks of 9 subject
95
Enter the marks of 10 subject
99
The average of 10 subjects is = 89.5
The truncated value of average of 10 subjects is = 90.0

Program Based On Inbuilt Function

WAP to find the Amount at Simple Interest when the user enters the Principle, Rate and Time. Print
1> Rounded value of Amount to the higher integer
2> Rounded value of Amount down to the nearest integer

Program :

import java.io.*;
public class inbuilt4
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);

System.out.println("Enter the Principle");
double p = Double.parseDouble(in.readLine());
System.out.println("Enter the Rate");
double r = Double.parseDouble(in.readLine());
System.out.println("Enter the Time");
double t = Double.parseDouble(in.readLine());

double I = (p*r*t)/100;
double A = p+I;

double Ahigh = Math.ceil(A);
double Alow = Math.floor(A);

System.out.println("The actual value of Amount is = "+A);
System.out.println("Rounded value of Amount to the higher integer is = "+Ahigh);
System.out.println("Rounded value of Amount down to the nearest integer = "+Alow);
}
}





Program Execution:

Enter the Principle
105
Enter the Rate
5
Enter the Time
1
The actual value of Amount is = 110.25
Rounded value of Amount to the higher integer is = 111.0
Rounded value of Amount down to the nearest integer = 110.0

Program Based On Inbuilt Function

WAP to accept degrees as input and print the print its sin, cos and tan.

Program :

import java.io.*;
public class inbuilt3
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);

System.out.println("Enter the degree");
double input = Double.parseDouble(in.readLine());
double radian = input*((22/7)/180);
double s = Math.sin(radian);
double c = Math.cos(radian);
double t = Math.tan(radian);

System.out.println("The sin of the angle is = "+s);
System.out.println("The cos of the angle is = "+c);
System.out.println("The tan of the angle is = "+t);
}
}


Program Execution:


Enter the Degree

The Sine of the Angle is =

The Cos of the Angle is =

The Tan of the Angle is =

Program Based On Inbuilt Function

WAP to accept two numbers find the largest and print its square root. And print the square of the smaller one.

Program:

import java.io.*;
public class inbuilt2
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
double square=0;

System.out.println("Enter the first number");
int one=Integer.parseInt(in.readLine());
System.out.println("Enter the second number");
int two=Integer.parseInt(in.readLine());

int large=Math.max(one,two);
int less = Math.min(one,two);
double squareroot=Math.sqrt(large);
square=Math.pow(less,2);

System.out.println("The square root of the larger number is = "+squareroot);
System.out.println("The square of the smaller number is = "+square);
}
}


Program Execution:

Enter the first number
100
Enter the second number
6
The square root of the larger number is = 10.0
The square of the smaller number is = 36.0

Program Based On Inbuilt Function

Wap to print square root of 1 to 10 in a chart


Program:

import java.io.*;
public class inbuilt1
{
public static void main(String args[])
{
double ans=0.0;
System.out.println("The square root of 1 to 10 is");

for(int i=1;i<11;i++) ans="(double)Math.sqrt(i);">Program Execution:

The square root of 1 to 10 is
1 1.0
2 1.4142135623730951
3 1.7320508075688772
4 2.0
5 2.23606797749979
6 2.449489742783178
7 2.6457513110645907
8 2.8284271247461903
9 3.0
10 3.1622776601683795

Bluej - Other Resources


  1. A Laboratory for Object-Oriented Thinking - paper about CRC cards

  2. Multiple Choice Questions - abank of 70 on-line self-test questions

  3. A set of tutorials for writing games in BlueJ - step by step...

  4. The BlueJ Crosswords - crossword puzzles about OO concepts

  5. A collection of course material - including slides and labs

  6. Java Tips - a collection of programming tips
  7. BlueJ-discuss forum
  8. Books: A Practical Introduction using BlueJ -David J. Barnes and Michael KöllingObjects First with Java - Third edition, Prentice Hall / Pearson Education, 2006ISBN 0-13-197-629X
    This is the BlueJ book straight from the source. David J. Barnes, author of a Java text book, and Michael Kölling, one of the authors of BlueJ, have written an introductory OOP textbook that completely integrates BlueJ in its Java introduction.

BlueJ Teaching and Learning Resources

Exercises:

1. Zork 1 - zork1.zip zork1 handout (text, pdf format): zork1.pdf

"Zork 1" is a skeleton of a simple adventure game. It is entirely text based, and users can enter commands such as "go north" to move through some rooms. The skeleton can be used as a starting point for an assignment.


2. Skodak's Draw Tutorial - Skodak's Draw Tutorial web page

"Skodak's Draw Tutorial " set of sample exercises suitable for teaching fundamentals of OOP and Java language, including accompanying source code and solutions. The exercises start with drawing simple shapes and lead to a keyboard controlled interactive game.


3. Self-Test Centre - Self-Test Centre Short Java programming exercises
A set of about 50 short Java programming exercises. Covers basic programming constructs, use of AWT components and utility classes. Exercises available as Word files.

4. Shapes Labs - shapes-labs.zip A collection of lab exercises using the shapes example
A set of 5 labs based on the shapes example, which is included in the BlueJ example projects (and also used in the Objects First book). Labs are available as Word files.

BlueJ Teaching and Learning Resources

Java Classes

1. Simple Input - SimpleInput.java

A Java class for getting input into a program in a simple manner. The class has methods such as getInt(prompt) or getString(prompt), which pop up an input window and return the result.

2. GUI/CUI - input classes - gui.java cui.java testguinput.java testcuinput.java

Modified and extended version of the SimpleInput class (above). It now accepts all nine fundamental variable types - : byte, short, int, long, float, double, char, String, and boolean . It ignores appropriate input errors smartly. It also gives a easy way to generate output through dialog boxes.

The file is named as gui.java , and accompanying testguinput.java uses it as a sample program.


Also includes a cui class which does the same thing through console input. The method formats are same for both cui and gui class. The accompanying file testcuinput.java uses it as a sample program.


Some highlights are : ( Applicable to both gui and cui classes )


If someone wants to input a integer type data into variable b , he simply writes: b = s1.getInt("Enter an integer no..."); s1 is the object generated from class gui/cui - say, gui s1 = new gui( );
If he wants to turn on the built in error correction code, he simply writes: s1.ecc ( true ); The default is false, if not mentioned , if made on , it ignores integer input error like 34p5 ( makes it simple 345 ).


If he wants to output something , say value of variable b, he simply writes: s1.show("You have entered : Byte = "+b) ;

3. Canvas - Canvas.java

Hints for use: Save the source file, then use the "Import Class" function in BlueJ to import this class into your project. Then it can be used like any other class.

See also: The Bouncing Ball example in the Demonstrations section demonstrates the use of this class.

A Java class for drawing into a window. This class provides output only (no events). It can be used to produce drawings and animations. Very simple to use.

4. stdio

  1. stdio.java (the source file, right-click or shift-click to save)
  2. stdio.class (the compiled class file)
  3. stdio.html (javadoc format documentation for stdio)
  4. StdioTest.java (a small example program for using stdio)
  5. stdio.jar (all of the above together in a single jar file)

stdio defines static methods for using typed input from the console window. This class includes two methods for getting a line of input, two methods for handling (i.e. parsing) typed-in numbers, and a simple rounding method so that System.out.println won't print "0.33333333333333333" when you want to see "0.33".

Hints for use: Put stdio.java and stdio.class into your project folder and then use stdio in your project as you would use any other class.

5. GWindow - gwindow.jar (the jar file contains the GWindow class, the demo class and documentation)

An implementation of a GUI window (JFrame) to test AWT/Swing components and graphics primitives. From the documentation: "This window will work properly if opened from within a JAR file that is executed from the DOS command line because it provides a method that allows a thread to wait until the window is closed."

Hints for use: See GWindowDemo for an example of how to use GWindow

6. AppletWindow - appletwn.jar (includes a simple demo class and a simple applet)


AppletWindow is a window framework that lets you run applets in a normal JFrame. This allows you to use the BlueJ debugger on your applet.

Hints for use: The .jar file includes a simple demo class and a simple applet. See the README.TXT file for complete instructions

7. Skodak's IO Helper for BlueJ - Skodak's IO Helper web page


"Skodak's IO Helper for BlueJ" is designed specially for BlueJ IDE to support teaching of basics of IO operations in Java. It is suitable for any other IDE or standalone execution of applications. It is not designed for Java applets.

8. Turtle Graphics

  1. TurtleE.zip (turtle library source code)
  2. BlueJTurtleE.zip (some examples of using the turtle)


This is an implementation of the good old turtle graphics package. Source code for the turtle library is available in English and German, and some examples are available (with German comments).

9. JEWL - http://www.it.brighton.ac.uk/staff/je/java/jewl


JEWL is GUI library for beginners which allows GUI-based programs to be used from the "Hello world" stage onwards.

Bluej Tutor

Documentation for specific extensions is available from the extensions page.

Source: http://bluej.org

Bluej - Download and Installation

Step 1: Get Java


Check the system requirements. Make sure you have an appropriate version of Java installed.

Step 2: Download the installation package


Latest official release:


BlueJ version 2.2.1

for Windows (3.6Mb) bluejsetup-221.exe
for MacOS X (3.2 Mb) BlueJ-221a.zip
all other systems (executable jar file) (3.1 Mb) bluej-221.jar


Note: If your browser tries to display the file, instead of downloading it, then use "Save link as.." which you get when you right-click or shift-click the link.

Once you have loaded the file, go to the Installation Instructions.

Step 3: Installation

Windows:

Double-click the install file (bluejsetup-221.exe).
This will run a standard installation. Follow the instructions on screen. The installer will install the executable bluej.exe. Execute this to run BlueJ.

If you have more than one Java version installed, BlueJ will let you select your preferred version the first time it is executed. This can be changed later by running the "vmselect" program, which will be installed into the same directory as BlueJ.


Macintosh:


Note: BlueJ requires Java 2 or later, and thus runs only on MacOS X. Updating to the latest Java version (via the Software Update feature) is recommended.


Download and expand the install file (BlueJ-221.zip). Move the resulting folder to your preferred location (for example Applications).


Unix:


Make sure you have a suitable JDK or J2SDK. The Sun JDK/J2SDK is recommended as it is the most well tested. Currently the "gij" (GNU java interpreter) cannot be used.


Run the installer by executing (from the command shell)


/path/to/jdk/bin/java -jar bluej-221.jar


... where "/path/to/jdk" should be replaced by the actual path to the JDK.


Note: if you have a suitable java binary in a directory listed in your PATH environment variable, you may be able to omit the "/path/to/jdk" above. Be careful that this does not run an incompatible java implementation (such as "gij") however! You can check if a Java implementation is in your path by runng "java -version".


In the installer, select an installation directory and your JDK directory and install. By default, the installer will install into a directory called "bluej" inside the directory from which you launch it, and it will pick up the JDK location automatically (if it is run correctly according to the instructions above).


In the directory where BlueJ was installed, you will find a file named bluej. This is the launcher script. Execute this script to start BlueJ. For example: cd bluej # change into installation directory


./bluej # execute the "bluej" launcher script


Note: This installer can be executed on any system with Java 2 installed (including Windows and MacOS), but Windows/MacOS specific icons and configurations will not be present.


Optional: Remove the Installer


If you do not want to make further installations, you can now delete the installer file.


Step 4: Opening a project

After starting BlueJ, open a project by selecting "Open" from the Project menu. You can find some examples in the "examples" directory. After the project has been opened, right-clicking (Mac: control-clicking) a class lets you select a constructor from a pop-up menu to construct an object.


Optional: Subscribe to mailing list


If you want to be notified of new releases, go to bluej-announce and subscribe.


If you are interested in general discussion of BlueJ-related questions, read or subscribe to bluej-discuss. There is also an archive of past messages that you can read without subscribing.


Where to from here?


If you have any trouble with the installation, please read How to ask for help.
If it all works this far, you might like to start reading the Tutorial.

Bluej - System Requirements

You need to have Java installed on your system. You need one of the following versions:

JDK 6, JDK 5 or J2SE 1.4.2

Note that you need the version labeled JDK, not JRE, or the Netbeans or EE versions.

Windows Vista users must use JDK 6 (read this for details).

Details about system requirements are here.
System Requirements for BlueJ 1.3 and above

Hardware requirements

Minimum: 64Mb main memory, Pentium II processor or equivalent
Recommended: 128Mb main memory, 400MHz Pentium III processor or above

Software requirements

J2SE 1.4.2 (Java 2 SDK version 1.4.2) or newer must be installed.
BlueJ versions up to version 1.3.0 also run on JDK 1.3.x.
BlueJ versions up to version 1.1.3 also run on JDK 1.2.2.

On MacOS X, a recent Java SDK version is installed by default. You do not need to install Java on this system.

Why BlueJ?

1. Introduction

Java is quickly becoming very popular, both for application development and for teaching, and many programming environments exist. This raises the question:

Why yet another programming environment?

The short answer is: because none of the existing environments is suitable for teaching.

In particular, we want an environment that is really object-oriented. An environment that emphasises classes and objects as its basic units of interaction, so that students are naturally led into a way of thinking in terms of classes and objects.

Secondly, we want an environment that is sophisticated, but at the same time easy to use, so that students can start using it straight away without the need for long introduction. We do not want to teach about the environment itself.

Thirdly, we want an environment that supports interaction and experimentation.

Fourthly, we want an environment that uses visualisation to display class structure. After all, half of the time in a teaching context we talk about class structure. Structuring the problem is one of the most important aspects of object-oriented programming. Yet many teachers find that students have difficulty thinking in terms of classes and objects. This is not surprising if all they ever see on the screen are lines of code or interface buttons and menus!

2. The problems with existing environments

Several aspects in existing environments cause a long list of problems in teaching. One or more of these problems is present in every other environment.

  • The environment is not really object-oriented.
    An environment for an object-oriented language does not make an object-oriented environment. The environment itself should reflect the paradigm of the language. In particular, the abstractions students work with should be classes and objects. In most existing environments, students deal with files instead. They are forced to think about the operating system's file system and directory structure. Setting up projects can be a nightmare. All this creates overhead that hinders teaching and distracts from the important issues. Objects as interaction entities are not supported in any other Java environment. Yet they are one of the most fundamental abstraction concepts.

  • The environment is under- or overkill.
    Many teachers do not use an integrated environment (usually because of problems with finding a suitable one). In that case, students work from a command line (using Sun's JDK) and spend considerable time becoming familiar with Unix or DOS instead of learning about programming. In this case, valuable opportunities are lost for better teaching and learning through the use of better tools. Other environments are developed for more professional users and present an absolutely overwhelming set of interface components and functionality. Students are lost in these environments, and the effect can be as bad as having no integrated environment at all. Other environments are really modifications of non-object-oriented (procedural) environments and offer the wrong set of tools and abstractions. All of those, too minimalist tools, too complicated tools or the wrong tools, cause considerable problems.

  • The environment focuses on user interfaces.
    Many environments using graphics use the graphics for the wrong tasks. In particular, many environments concentrate on building graphical user interfaces (GUIs). Building GUIs from the start conveys a very distorted picture of programming and object-orientation. Students spend their time dragging buttons rather than thinking about building an application.

    At the same time a much more beneficial use of graphics is neglected: display of class structure. Object-oriented program structure can be represented graphically in a way that makes it easier to understand. Few existing environments make good use of this.

  • The environment is expensive.
    Cost is still a big problem with some environments. One effect of this is the problem for students to work at home - acquiring a license for home use can be expensive.

3. The BlueJ solutions

BlueJ addresses all of these problems:

  • BlueJ is object-oriented.
    In BlueJ students interact with classes and objects. They can manipulate class structure graphically and textually. Objects can be created and methods of any object can be called interactively.

  • BlueJ has been designed for teaching.
    BlueJ offers a unique mix of sophisticated support for visualisation and interaction and a simple and intuitive interface.

  • BlueJ visualises class structure and objects.
    In BlueJ, class structure can be seen and manipulated on screen, and objects can be interactively created and operations called.

  • BlueJ is free.
    The environment is available free of charge.

4. Problems with Java (and BlueJ's answers)

Java is a reasonably clean language, but by no means free of problems for introductory teaching. For teachers, it is important to know those problems and to have a way to deal with them. Two of the problems most often reported in the literature (for example in [1] and [4]) are:

  • problems with the main function
  • problems with text I/O


The main function: The main function has to be written with the signature

public static void main (String[] args)

This causes several problems. Firstly, several concepts are used here which cannot be explained at this stage (static functions, arrays, void return types). So teachers have to use some hand-waiving ("just believe me and write it like this") and students feel frustrated. Secondly, this has nothing to do with object-orientation! The main function does not logically belong to any object. Thus, students start off with seeing an exception rather than a good example of object-orientation.

I/O: Text I/O, especially input, is not simple and causes regular problems. In addition, it forces students to deal with exceptions at a very early stage.

BlueJ solves both of these problems!

Because objects can be created interactively, and methods can be called interactively, there is no need for a main function. Students can write classes and call their methods without a need to have a main. And because parameters can be passed to interactive method calls and results are displayed, there is no immediate need for I/O. Students can write and test very sophisticated code without the need for any I/O operations!

5. Real object-oriented teaching

Many Java text books claim to use an "objects first" approach. We very much agree with this idea. In reality, most of the books then go on to explain some low level instructions first and get to objects and classes in chapter four. The reason is an intrinsic problem with Java: if you explain classes first, then you still need a way to execute the class's operations to see a result. And to do this you have to write some driver code. To write this code, you need to know some Java instructions.

In BlueJ, no driver code is needed. Operations can be invoked interactively, so teachers are free to use a real objects-first approach for the first time. Students can be given a class of which they can create objects. They can use those objects. Then they can open them and read, modify or add operations. This is really "objects first" with the introduction of lower level constructs after methods (as a means to implement those methods).

Source:http://bluej.org

About BlueJ

BlueJ is an integrated Java environment specifically designed for introductory teaching.

BlueJ was developed at a University specifically for the purpose of teaching object orientation with Java. BlueJ is free!

The BlueJ environment was developed as part of a university research project about teaching object-orientation to beginners. The system is being developed and maintained by a joint research group at Deakin University, Melbourne, Australia, and the University of Kent in Canterbury, UK. The project is supported by Sun Microsystems.


The aim of BlueJ is to provide an easy-to-use teaching environment for the Java language that facilitates the teaching of Java to first year students. Special emphasis has been placed on visualisation and interaction techniques to create a highly interactive environment that encourages experimentation and exploration.


BlueJ supports:

  • fully integrated environment
  • graphical class structure display
  • graphical and textual editing
  • built-in editor, compiler, virtual machine, debugger, etc.
  • easy-to-use interface, ideal for beginners
  • interactive object creation
  • interactive object calls
  • interactive testing
  • incremental application development

BlueJ is based on the Blue system. Blue is an integrated teaching environment and language, developed at the University of Sydney and Monash University, Australia. BlueJ provides a Blue-like environment for the Java language.


The BlueJ project started at Monash University in Melbourne, and later split and migrated to its current locations.


BlueJ is implemented in Java, and regularly being tested on Solaris, Linux, Macintosh, and various Windows versions. It should run on all platforms supporting a recent Java virtual machine.

Program Based On User Defined Function

WAP to accept the temperature as 1> Fahrenheit, and 2> Kelvin. Invoke a method celsius(int); celsiusK(int) to convert the temperature into Celsius.

Program :

import java.io.*;
public class function5
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);


System.out.println("Enter your Choice");
int choice = Integer.parseInt(in.readLine());

switch (choice)
{
case 1:
System.out.println("Enter the temperature in Fahrenheit");
double fah = Double.parseDouble(in.readLine());
celcius(fah);
break;

case 2:
System.out.println("Enter the temperature in Kelvin");
double k=Double.parseDouble(in.readLine());
celciusK(k);
break;
default:
System.out.println("Enter a valid choice");
break;
}
}
public static void celcius(double a)
{
double c;
c = (double)((a-32)/9)*5;
System.out.println("The temperature in Celsius is = "+c);
}

public static void celciusK(double b)
{
double c2;
c2 = (double)b-273;
System.out.println("The temperature in Celcius is = "+c2);
}

}


Program Execution:

Enter your Choice
1
Enter the temperature in Fahrenheit
96.9
The temperature in Celsius is = 36.05555555555556

Program Based On User Defined Function

WAP in JAVA to find the sum of the series using the function name fact(int m) to return the factorial of m
S=1+a^2/2!+a^4/4!----------------------+a^n/n!;


Program:

import java.io.*;
public class function4
{
public static int fact(int m)
{
int prod=1;
for(int i=1;i<=m;i++)
{
prod=prod*i;
}
return prod;
}

public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
System.out.println("Enter the value of n");
int n = Integer.parseInt(in.readLine());
System.out.println("Enter the value of a");
int a = Integer.parseInt(in.readLine());

int p=0;
double pow=0.0;
double s=0.0;
for(int j=0;j<=n;j=j+2)
{
p=fact(j);
pow=Math.pow(a,j);
s=(double)s+p/pow;
}
System.out.println("The Sum of The Series is = "+s);
}

}


Program Execution:


Enter the the value of n
10
Enter the the value of a
1
The Sum of The Series is = 3669867.0

Program Based On User Defined Function

WAP in JAVA to find the sum of the series using function name fact(int a) which returns factorial of the number a.
S = 1+1/2!+1/3!+----------------------+1/n!

Program :

import java.io.*;
public class function3
{
public static int fact(int a)
{
int prod=1;
for(int i=1;i<=a;i++)
{
prod=prod*i;
}
return prod;
}

public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);
System.out.println("Enter the limit");
int n = Integer.parseInt(in.readLine());
int p=0;
double s=0;
for(int j=1;j<=n;j++)
{
p=fact(j);
s=(double)1/p;
}

System.out.println("The Sum of The Series is = "+s);
}
}



Program Execution :


Enter the limit
10
The Sum of The Series is = 2.755731922398589E-7

Program Based On User Defined Function

Write a program in JAVA to find the sum of the series using function name product(int,int) to return the product of two numbers in order to obtain each term.
S= (1*2)+(2*3)+(3*4)+-----------------------------+(9*10)

Program :
import java.io.*;
public class function2
{
public static int product(int a,int b)
{
int c=0;
c=a*b;
return c;
}

public static void main(String args[])
{
int s=0;
int k=0;
for(int i=1;i<=9;i++)
{
k=product(i,i+1);
s=s+k;
}

System.out.println("The Sum of The Series is = "+s);

}

}


Program Execution:

The Sum of The Series is = 330

Program Based On User Defined Function

WAP in JAVA to accept a number and check whether it is an Automorphic number or not using function name digit(int n) which return number of digit present in the number.

Program:
import java.io.*;
public class function1
{
public static int digit(int n)
{
int c=0;
int k=0;
while(n!=0)
{
k=n/10;
c++;
n=k;
}
return c;
}

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

System.out.println("Enter Your Number");
int a=Integer.parseInt(in.readLine());

double a1=a;
int p=0;
int b=0;
int c=0;
double r=0.0;

p=a*a;
b=digit(a);
r=p%(Math.pow(10,b));
if(a1==r)
System.out.println("The Number "+a+" is Automorphic");
else
System.out.println("The Number "+a+" is not Automorphic");
}
}


Program Execution:

Enter Your Number
25
The Number 25 is Automorphic

Programs Based On Strings

Wap to accept a sentence or a word.Change the sentence that every alphabet
becomes the next one.
e.g. A->B
B->C.......
Z->a
a->b.....
z->A.

Program:
import java.io.*;
public class string
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);

System.out.println("Enter the sentence or word");
String sentence=in.readLine();
System.out.println();
System.out.println();
System.out.println("The new sentence or word is");
System.out.println();
System.out.println();
int len=sentence.length();
int val=0;
int sp=0;
char character;

for(int i=0;i {
char ch=sentence.charAt(i);
val=(int)ch;
if(val==90)
{
sp=97;
character=(char)sp;
System.out.print(character);
}
if(val==122)
{
sp=65;
character=(char)sp;
System.out.print(character);
}
if((val!=122)&&(val!=90))
{
sp=val+1;
character=(char)sp;
System.out.print(character);
}
}
}
}


Program Execution:

Enter the sentence or word
Sangam

The new sentence or word is
Tbohbn

Programs Based On Strings

Wap to accept a sentence or a word.Change the sentence that every alphabet
becomes the next one.
e.g. A->B
B->C.......
Z->a
a->b.....
z->A.

Program:
import java.io.*;
public class string
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);

System.out.println("Enter the sentence or word");
String sentence=in.readLine();
System.out.println();
System.out.println();
System.out.println("The new sentence or word is");
System.out.println();
System.out.println();
int len=sentence.length();
int val=0;
int sp=0;
char character;

for(int i=0;iProgram Execution:

Enter the sentence or word
Sangam

The new sentence or word is
Tbohbn

Programs Based On Strings

WAP to accept a word and find the longest word in the sentence.

Program:
import java.io.*;
public class string4
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);

System.out.println("Enter the Sentence");

String sentence = in.readLine();
sentence=sentence+" ";
int len=sentence.length();
int len1=0; int len2=0; int large=0; int sp=0;
String word="";
String word1="";
String word2="";
for(int j=0;j {
char c=sentence.charAt(j);
if(c==' ')
{
word=sentence.substring(sp,j);
len1=word.length();
word2=word;
break;
}
}

for(int i=0;i {
char ch=sentence.charAt(i);
if(ch==' ')
{
word1=sentence.substring(sp,i);
len2=word1.length();
sp=i+1;

if(len2>len1)
{
large=len2;
word2=word1;
}
}
}

int ans=Math.max(large,len1);
System.out.println();
System.out.println("The longest word is = "+word2);
System.out.println("The longest word has "+ans+" alphabets");
}
}


Program Execution

Enter the Sentence
Albert Einstein is the greatest scientist of the world.

The longest word is = scientist
The longest word has 9 alphabets

Programs Based On Strings

WAP to accept a name and print the short form of the name.
e.g. INPUT: Gautam Kumar OUTPUT: G. Kumar

Program :
import java.io.*;
public class string3
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);

System.out.println("Enter your name");
String name = in.readLine();
int len = name.length();
name=name+" ";
String word,word1,word2,frame; word=""; word1=""; word2=""; frame="";
int count=0; int count1=0;
int sp=0; int sp1=0;
char initial;

for(int i=0;i {
char ch = name.charAt(i);
if(ch==' ')
{
word=name.substring(sp);
sp=i+1;
count++;
}
}
String name1=" "+name+".";
int len1=name1.length();
for(int j=0;j {
char ch1 = name1.charAt(j);
if((ch1==' ')&&(count1 {
count1++;
initial=name1.charAt(j+1);
word2=word2+initial+"."+" ";
sp1=j+1;
}
if((ch1==' ')&&(count1==count))
{
sp1=j+1;
}
if(ch1=='.')
{
word1=name1.substring(sp,j);
frame=word2+word1;
}
}
System.out.println();
System.out.println("The short form of your name is = "+frame);
}
}


Program Execution

Enter your name
Sachin Ramesh Tendulkar

The short form of your name is = S. R. Tendulkar

Programs Based On Strings

WAP to accept astring and find the frequency of the word present in the string.
SAMPLE INPUT : Tata Steel is one of the Steel manufacturing company of the country;
Frequency of the word to be searched : the
OUTPUT : 2

Program:
import java.io.*;
public class string2
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);

String word="";
int sp=0;
int c=0;

System.out.println("Enter your String");
String sentence = in.readLine();
sentence=sentence+" ";
int len=sentence.length();
System.out.println("Enter the word whose frequency is to be found");
String search = in.readLine();

for(int i=0;i {
char ch=sentence.charAt(i);
if (ch==' ')
{
word = sentence.substring(sp,i);
sp=i+1;

if(word.equalsIgnoreCase(search)==true)
{
c++;
}
}
}

System.out.println("The number of substring "+search+" in the string is "+c);
}
}


Program Execution

Enter your String
Einstein was called the best scientist the Germans and the world has witnessed.
Enter the word whose frequency is to be found
theThe number of substring the in the string is 3

Programs Based On Strings

WAP in Java to accept a word and display the same word in Pig Latin form.
Sample Input: trouble
Output: oubletray

Program :
import java.io.*;
public class string1
{
public static void main(String args[])throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(read);

System.out.println("Enter the word");

String x=in.readLine();
String word = "";
String word2 = "";
String frame = "";
int sp=0;
int len = x.length();
int p=len+1;

for(int i=0;i {
char ch=x.charAt(i);
if((ch=='a')(ch=='e')(ch=='i')(ch=='o')(ch=='u')(ch=='A')(ch=='E')(ch=='I')(ch=='O')(ch=='U'))
{
word=x.substring(sp,i);
word2=x.substring(i,len);
}
frame=word2+word+"ay";
}
System.out.println(frame);
}
}

Program Execution

Enter the word
Sangam
The word in PigLatin is = amSangay


Search the web
Custom Search


All Rights Reserved