This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

anandhi mohan

Greenhorn
+ Follow
since Mar 24, 2009
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by anandhi mohan

Try This,

11 years ago
try this code:



your n value should be starting from 1.
11 years ago
In your code

while(true)
{

for(....)
{
if(condition)
{

break

}
}

}

you are using break inside for loop so It will come out from forloop only not from while loop . If you want to break the while loop
then you can set flag to break it.


try this:



class dotcomm
{

public static void main(String[] args)
{
dd d = new dd();
d.game();
}
}

class dd
{

int hit = 0;
int[] locations =
{
2, 3, 4
};

void game()
{
boolean flag = true;
while (flag)
{
int userg = (int) (Math.random() * 4);
System.out.println("the guess is" + userg);
for (int num : locations)
{
if (userg == num)
{
System.out.println("successful");
//hit++;
//System.out.println("the num of hits ="+ hit);
flag = false;
break;

}
}
if (flag)
{
System.out.println("does not match,TRY AGAIN");
}
}
}
}
11 years ago
If your program throws any exceptions then it will handle by try catch block and it wont be affect the entire program.
It will be continue the process until it reaches the end.

finally block does not consider about the exception . It will be excuting even there is no exception in program
11 years ago
you can use same buffer reader to get different input.
In your code, you are closing the bufferreader before it reads the input thats why it throws some exceptions.

try this:

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try
{
String a;
System.out.println("Enter Name");
a=br.readLine();
nme=a;
System.out.println("Enter Amount");
a=br.readLine();
bn=Double.parseDouble(a);
System.out.println("Enter rollno.");
a=br.readLine();
double x=Double.parseDouble(a);
Long ac_no=(long)x;
br.close();
}
catch(Exception e)
{

System.out.println("Exception encountered");
}
11 years ago
try this:

String stro = str8.replaceAll("\\{.*\\}", "00000");

{ & } - are special characters.So you have to use \\ like \\{
11 years ago
try this

class WordsCountComparator implements Comparator<String> {

public int compare(String o1, String b) {
return 1;
}
}

compare method Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
If you want to get the output in same order as input then you have to override the compare method that will always return 1.
11 years ago
use this pattern to get list of books

((?<=(<Book>))[^<]*(?=</Book>))

(?<=(<Book>) - this is used to check whether the string is starting with <Book> or not. and then <book> will not displayed in result
(?=</Book>) - to check whether the string is ending with </Book> or not. This is also not included in output.
^ -The pipe is used for the "OR" operation in regex, to use it as a literal you have to escape it.
11 years ago

//Try this code to get output like 10 150

class Wrappers{
static Integer newInt = null;
public static void changeIntVal(Integer aInt){
newInt = aInt * 15;
}

public static void main(String[] args){
newInt = new Intger(10);
System.out.println(newInt);
Wrappers.changeIntVal(newInt);
System.out.println(newInt);
}
}

// //
Wrappers.changeIntVal(newInt);
You are passing only value of newInt to that changeIntVal method ,not the variable.
and you cannot access that variable from outside because it is local to the main method.
If you want to access the variable from anywhere in the class then you can use static
11 years ago

David Newton wrote:

anandhi mohan wrote:use this to get the list index for your given input.

int c= l.indexOf(a);


List has an indexOf() method?



yes, list has this method.
11 years ago
use this to get the list index for your given input.

int c= l.indexOf(a);
11 years ago