Java code to reverse a word or sentence ending with using recursion

/*
Program to reverse a word or sentence ending with . using recursion
*/
import java.io.*;
class reverseWord
{
static BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
public static void main(String args[]) throws IOException
{
reverseWord call = new reverseWord();
System.out.print("Enter characters & . to end : ");
call.print();
}
void print() throws IOException
{
char c = (char)br.read();
if(c!=.)
{
print();
System.out.print(c);
}
}
}


/**
* ALGORITHM :
* ---------
* 1. Start
* 2. Accept a sentence from user with full-stop(.) at the end.
* 3. Using recursion, print the sentence in reverse order.
* 4. End
*/

/*
OUTPUT :
------
Enter characters & . to end : stressed.
desserts
*/


Read More..

Android Audio Demo AudioTrack AudioRecord Echo Sample

Simple echo application for how to use android AudioTrack and AudioRecord classes
Download Source
Step 1
    Create MainActivity class for audio record and play

package com.javaorigin.audio;

import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioRecord;
import android.media.AudioTrack;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {
AudioManager am = null;
AudioRecord record =null;
AudioTrack track =null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setVolumeControlStream(AudioManager.MODE_IN_COMMUNICATION);
init();
(new Thread() {
@Override
public void run() {
recordAndPlay();
}
}).start();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

private void init() {
int min = AudioRecord.getMinBufferSize(8000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
record = new AudioRecord(MediaRecorder.AudioSource.VOICE_COMMUNICATION, 8000, AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT, min);

int maxJitter = AudioTrack.getMinBufferSize(8000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
track = new AudioTrack(AudioManager.MODE_IN_COMMUNICATION, 8000, AudioFormat.CHANNEL_OUT_MONO,
AudioFormat.ENCODING_PCM_16BIT, maxJitter, AudioTrack.MODE_STREAM);
}

private void recordAndPlay() {
short[] lin = new short[1024];
int num = 0;
am = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
am.setMode(AudioManager.MODE_IN_COMMUNICATION);
record.startRecording();
track.play();
while (true) {
num = record.read(lin, 0, 1024);
track.write(lin, 0, num);
}
}

boolean isSpeaker = false;

public void modeChange(View view) {
Button modeBtn=(Button) findViewById(R.id.modeBtn);
if (isSpeaker == true) {
am.setSpeakerphoneOn(false);
isSpeaker = false;
modeBtn.setText("Call Mode");
} else {
am.setSpeakerphoneOn(true);
isSpeaker = true;
modeBtn.setText("Speaker Mode");
}
}

boolean isPlaying=true;
public void play(View view){
Button playBtn=(Button) findViewById(R.id.playBtn);
if(isPlaying){
record.stop();
track.pause();
isPlaying=false;
playBtn.setText("Play");
}else{
record.startRecording();
track.play();
isPlaying=true;
playBtn.setText("Pause");
}
}

}
Step 2
        Add Button for Play/Pause and Call mode/ Speaker mode
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >



<Button
android:id="@+id/modeBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="24dp"
android:text="Call Mode"
android:onClick="modeChange"/>

<Button
android:id="@+id/playBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/modeBtn"
android:layout_alignBottom="@+id/modeBtn"
android:layout_marginLeft="30dp"
android:layout_toRightOf="@+id/modeBtn"
android:onClick="play"
android:text="Pause" />

</RelativeLayout>

Step 3
    Add audio related permission to Android.xml
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"></uses-permission>
    <uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
Read More..

The C code for a circular permutation

The C++ code for a circular permutation.   The code was compiled with CodeBlocks and above is the code and the output.

Read More..

3D wallpaper created by 23ars in Photoshop


Read More..

FREE eBook Your Unofficial Raspberry Pi Manual

Raspberry Pi: The Unofficial Tutorial, By Christian Cawley, http://www.makeuseof.com


Get to know the world’s favorite $25 computer: the Raspberry Pi. You’ll find tips, tricks and more in this unofficial Raspberry Pi tutorial from MakeUseOf. Whether you’re a current Pi owner who wants to learn more or a potential owner of this credit-card size device, this isn’t a guide you want to miss.

Table Of Contents
  • §1 – The Raspberry Pi
  • §2 – What’s Inside the Raspberry Pi?
  • §3 – What You Will Need for Your Raspberry Pi
  • §4 – Setting Up the Raspberry Pi
  • §5 – Getting to Grips with the GUI
  • §6 – Programming on the Pi
  • §7 – Configuring the Raspberry Pi as a Media Centre
  • §8 – Fascinating Uses for the Raspberry Pi
  • §9 – Raspberry Pi: A Versatile Mini Computer
  • §10 – The Cream on Your Raspberry Pi

Download Link: http://www.makeuseof.com/pages/great-things-small-package-your-unofficial-raspberry-pi-manual

Read More..

Sharpen bitmap using Convolution

The previous exercise "Blur bitmap using Convolution". By changing the matrix of Convolution class, we can use it to sharpen bitmap.

 class Convolution {

// matrix to sharpen image
int[][] matrix = { { 0, -1, 0 }, { -1, 5, -1 }, { 0, -1, 0 } };
...


Sharpen bitmap using Convolution




more: Something about processing images in Android

Read More..

Type face Example In Android

Description:
This example shows you can use your own typeface font and use into your application.
Algorithm:
1.) Create a new project by File-> New -> Android Project name it TypefaceExample.
2.) Write following code into res/layout.main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">
    <TextView

       android:id="@+id/CustomFontText"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:textSize="30sp"
       android:text="Typeface Activity!!!! This is font Typeface example">
        </TextView>
</LinearLayout>
3.) Create a fonts folder into assets directory and put your font file i.e. “.otf” file there.
4.) Run for output.
Steps:
1.) Create a project named TypefaceExample and set the information as stated in the image.
Build Target: Android 2.1
Application Name: TypefaceExample
Package Name: com.org.typefaceexample
Activity Name: TypefacActivity
Min SDK Version: 7
2.) Open TypefaceActivity.java file and write following code there:
package com.org.typefaceexample;
import org.pack.R;
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;
public class TypefaceActivity extends Activity {
        @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Typeface tf = Typeface.createFromAsset(getAssets(),
                "fonts/File.otf");
        TextView tv = (TextView) findViewById(R.id.CustomFontText);
        tv.setTypeface(tf);
    }
}
3.) Compile and build the project.
Output
Read More..

Blog Archive

Powered by Blogger.