This is the method which will reverse the given STRING :
public void myOwnstringReversing(String str)
{
for(int i=str.length()-1;i>=0;i--)
{
System.out.print(str.charAt(i));
}
}
CONTENT WARNING:
This is my own program.. It is for Educational purposes only. Anyone do not republish in your website will be punished offensively.
Java programs for beginners, list of programs in java on various topics, interesting programs in java. Java programs on various topics
Friday, February 22, 2013
Reverse String in JAVA
Wednesday, December 19, 2012
Thread Program four in Java
public class Thread_Demo extends Thread{
public void run(){
System.out.println("Some text");
}
public static void main(String[] args) throws InterruptedException{
Thread_Demo t=new Thread_Demo();
Thread_Demo td1=new Thread_Demo();
t.start();
System.out.println("ISALIVE :"+t.isAlive());
t.sleep(500);
System.out.println("ISALIVE :"+t.isAlive());
//t.destroy();
t.resume();
System.out.println("ISALIVE :"+t.isAlive());
}
}
Thread Program three in Java
What is out put?
public class Thread_Demo extends Thread{
public void run(){
System.out.println("Some text");
}
public static void main(String[] args) throws InterruptedException {
Thread_Demo t=new Thread_Demo();
Thread_Demo td1=new Thread_Demo();
t.run();
System.out.println("ISALIVE :"+t.isAlive());
t.sleep(500);
System.out.println("ISALIVE :"+t.isAlive());
t.destroy();
System.out.println("ISALIVE :"+t.isAlive());
}
}
Thread Program Two in Java
What is output?
public class Thread_Demo extends Thread{
public void run(){
System.out.println("Some text");
}
public static void main(String[] args) throws InterruptedException {
Thread_Demo t=new Thread_Demo();
Thread_Demo td1=new Thread_Demo();
t.start();
System.out.println("ISALIVE :"+t.isAlive());
t.sleep(500);
System.out.println("ISALIVE :"+t.isAlive());
t.destroy();
System.out.println("ISALIVE :"+t.isAlive());
}
}
public class Thread_Demo extends Thread{
public void run(){
System.out.println("Some text");
}
public static void main(String[] args) throws InterruptedException {
Thread_Demo t=new Thread_Demo();
Thread_Demo td1=new Thread_Demo();
t.start();
System.out.println("ISALIVE :"+t.isAlive());
t.sleep(500);
System.out.println("ISALIVE :"+t.isAlive());
t.destroy();
System.out.println("ISALIVE :"+t.isAlive());
}
}
Thread Program in Java
What is out put?
public class Thread_Demo extends Thread{
public void run(){
System.out.println("Some text");
}
public static void main(String[] args) throws InterruptedException {
Thread_Demo td=new Thread_Demo();
Thread_Demo td1=new Thread_Demo();
/*Thread t=new Thread(td);*/
td.start();
td.setPriority(10);
System.out.println(td.getName()+td.getPriority());
td1.run();
System.out.println(td1.getName()+td1.getPriority());
}
}
public class Thread_Demo extends Thread{
public void run(){
System.out.println("Some text");
}
public static void main(String[] args) throws InterruptedException {
Thread_Demo td=new Thread_Demo();
Thread_Demo td1=new Thread_Demo();
/*Thread t=new Thread(td);*/
td.start();
td.setPriority(10);
System.out.println(td.getName()+td.getPriority());
td1.run();
System.out.println(td1.getName()+td1.getPriority());
}
}
Sunday, December 16, 2012
File Creation in java
import java.io.File;
import java.io.IOException;
public class FileCreatin {
public static void main(String args[]) throws IOException
{
File f=new File("F:/java.txt");
if(!f.exists())
{
f.createNewFile();
System.out.println("file created successfully");
}
else
System.out.println("File already exists");
}
}
import java.io.IOException;
public class FileCreatin {
public static void main(String args[]) throws IOException
{
File f=new File("F:/java.txt");
if(!f.exists())
{
f.createNewFile();
System.out.println("file created successfully");
}
else
System.out.println("File already exists");
}
}
Simple Java programs
1.
Question :
Given two non-negative int values, return true if they have the same last digit, such as with 27 and 57. Note that the % "mod" operator computes remainders, so 17 % 10 is 7.
Ans:
public boolean lastDigit(int a, int b) {
int r=a%10;
int r1=b%10;
if(r==r1)
{
System.out.println(true);
} // These programs for educational purpose only. Dont copy and publish in your blog or website..
else
System.out.println(false);
}
2.
Question :Given 2 int values, return true if one is negative and one is positive. Except if the parameter "negative" is true, then return true only if both are negative.
Ans:
public boolean posNeg(int a, int b, boolean negative) {
if((a<0&b>0&negative==false)|(a>0&b<0&negative==false))
{
System.out.println(true);
}
else if(a<0&b<0&negative==true)
System.out.println(true);
else
System.out.println(false);
} // These programs for educational purpose only. Dont copy and publish in your blog or website..
3.
Question :
Given two temperatures, return true if one is less than 0 and the other is greater than 100.
icyHot(120, -1) → true
icyHot(-1, 120) → true
icyHot(2, 120) → false
Answer:
public boolean icyHot(int temp1, int temp2) {
if((temp1<0&temp2>100)|(temp1>100&temp2<0))
{
System.out.println(true);
}
else
System.out.println(false);
} // These programs for educational purpose only. Dont copy and publish in your blog or website..
Question :
Given two non-negative int values, return true if they have the same last digit, such as with 27 and 57. Note that the % "mod" operator computes remainders, so 17 % 10 is 7.
Ans:
public boolean lastDigit(int a, int b) {
int r=a%10;
int r1=b%10;
if(r==r1)
{
System.out.println(true);
} // These programs for educational purpose only. Dont copy and publish in your blog or website..
else
System.out.println(false);
}
2.
Question :Given 2 int values, return true if one is negative and one is positive. Except if the parameter "negative" is true, then return true only if both are negative.
Ans:
public boolean posNeg(int a, int b, boolean negative) {
if((a<0&b>0&negative==false)|(a>0&b<0&negative==false))
{
System.out.println(true);
}
else if(a<0&b<0&negative==true)
System.out.println(true);
else
System.out.println(false);
} // These programs for educational purpose only. Dont copy and publish in your blog or website..
3.
Question :
Given two temperatures, return true if one is less than 0 and the other is greater than 100.
icyHot(120, -1) → true
icyHot(-1, 120) → true
icyHot(2, 120) → false
Answer:
public boolean icyHot(int temp1, int temp2) {
if((temp1<0&temp2>100)|(temp1>100&temp2<0))
{
System.out.println(true);
}
else
System.out.println(false);
} // These programs for educational purpose only. Dont copy and publish in your blog or website..
Subscribe to:
Posts (Atom)