Java | JSP | JSF Answers

Questions: 4 418

Answers by our Experts: 3 943

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

How can I compare two strings a character at a time and have it return string 1 if more than one letter is different?
Every time i run the loop the count is off by 1 and one of the inputs is not being added to the sum. Heres my code :
import java.util.Scanner;
public class InputSequence
{
public static void main (String[] args)
{
int sum = 0;
int count = 1;
int input = 0;
System.out.println("Enter integers, enter non integer to compute sum of input");
Scanner scan = new Scanner(System.in);
while (scan.hasNextInt())
{
input = scan.nextInt();
if ( scan.hasNextInt())
{
sum = input + sum;
count++;
}
else
{
System.out.println("You have entered " + count + " integers, the sum is " + sum);
}
}
}
}
I have a JButton that is suppose to remove JLabels when pressed. Everything I have tried in actionPerformed does not work. All I get are errors for button and labels.
i am writing a 2D array of integers to represent a swamp, heres the question
write a 2D array of integers to represent a swamp. Every value of 0 represents quicksand while every value of 1 represents solid ground. Your job will be to follow the trail of 1's (solid ground) to the edge of the swamp - or until it dead ends. You will take one step at a time in any direction as long as that step is onto solid ground ( 1 ), and not into quicksand ( 0 ). Put simply, you are dropped into the swamp onto a block of solid ground and starting there must follow the trail of safe steps one at a time until you either reach the edge of the swamp (rescued) or reach a dead end (stranded). You are guaranteed the following: 1) There are no cycles in your path to freedom or dead end (thus no backtracking/recursion needed). 2) You will start out on a block of solid ground. 3) There is only one possible path to take, and thus only one possible correct output for any given swamp.

heres what i have so far....

/*
Program9.java

*/

import java.io.*;
import java.util.*;


public class Program9
{
public static void main(String[] args)
{
int myRow=2, myCol=3; // you are dropped into the swamp at: [2][3]

int[][] swamp1 =
{
{ 0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,1 },
{ 0,0,0,1,0,0,0,0,1,0 },
{ 0,0,0,1,0,0,0,1,0,0 },
{ 0,0,0,0,1,0,1,0,0,0 },
{ 0,0,0,0,1,0,0,1,0,0 },
{ 0,0,0,0,1,0,0,0,1,0 },
{ 0,0,0,0,0,1,0,1,0,0 },
{ 0,0,0,0,0,0,1,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0 }
};

printSwamp( "SWAMP1",swamp1 );
printEscapePath( swamp1, myRow,myCol );


// Now swamp2

myRow=2; myCol=8; // you are dropped into the swamp at [2][8]

int[][] swamp2 =
{
{ 0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0 },
{ 0,0,1,0,0,0,0,1,1,0 },
{ 0,0,0,1,0,0,1,0,0,0 },
{ 0,0,0,0,1,1,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0 }
};

printSwamp( "\nSWAMP2",swamp2 );
printEscapePath( swamp2, myRow,myCol );

} // END MAIN

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

private static void printSwamp(String label, int[][] swamp )
{

System.out.println( label );
for(int r = 0; r < swamp.length; r++)
{
for(int c = 0; c < swamp[r].length; c++)
System.out.print( swamp[r][c] + " ");
System.out.println();
}
}



private static void printEscapePath(int[][] swamp, int myRow, int myCol)
{

int[] coords = new int[2];
coords[0]=myRow;
coords[1]=myCol;

System.out.println("STARTING AT: " + "["+ myRow + "][" + myCol + "]");

while ( !onEdge( swamp, coords ) )
{

if ( nextStep( swamp, coords ) )
{
System.out.println( "STEPPED TO: [" + coords[0] + "][" + coords[1] + "]" );
}
else // YOU'RE CROC MEAT :=(
{
System.out.println( "STRANDED AT: [" + coords[0] + "][" + coords[1] + "]" );
return;

} // END WHILE NOT OUT OF SWAMP YET

System.out.println( "ESCAPED AT: [" + coords[0] + "][" + coords[1] + "]" );

} // END PRINT ESCAPE PATH

// ########################################…
This is what i have so far, now how do i write the method that

// LOOKS AT EVERY ADJACENT SQUARE TO SEE IF IT'S A 1
// IF IT IS, THEN THE CURRENT X,Y IS CHANGED TO -1 (i.e. BEEN HERE)
// AND THE COORDS ARE CHANGED TO THOSE OF THE NEARBY SQAURE WITH A 1 IN IT
// IF NO SAFE STEP IS FOUND THEN JUST RETURN FALSE.
How to send and receive a secured SMS in java?
In a particular factory, a team leader is an hourly paid production worker that leads a small team. In addition to hourly pay, team leaders earn a fixed monthly bonus. Team leaders are required to attend a minimum number of hours of training per year. Design a TeamLeader class that extends the ProductionWorker class. The TeamLeader class should have fields for the monthly bonus amount, the required number of training hours, and the number of training hours that the team leader has attended. Write one or more constructors and the appropriate accessor and mutator methods for the class.
Demonstrate the class by writing a program that uses a TeamLeader object.
A file containing information about fruits is structured as follows. Apple Green Yellow Banana The file consists of tags and data. An opening and closing tag pair, ... , define a particular data element. Each fruit has a type and a color. Notice that either may appear first within the ... tags.Your program should read a file called “fruit.txt” with the above structure. The output of your program should be the number of each type of fruit, and the total pieces of fruit. For example, the output using the lines above is:

Number of type Apple: 1
Number of type Banana: 1
Total pieces of fruit: 2
Your program should be flexible enough to handle a file containing an indeterminate number of fruit descriptions. However, you may assume that there will be no more than 100 different types of fruit.
Output first x values in the fibonacci sequence, where x is an argument to the program.

0, 1, 1, 2, 3, 5, 8, ...

Write the fibonacci creation function separate from the main function. The main function will invoke the fibonacci function. fibonacci function returns a fully populated array of fibonacci numbers for the size passed to it.
Write a java source code that would compute the 4 arithmeti operators such as addition, subtraction,difference, and qoutient of the two given number. input the firrst number and second number named it as NUM1 and NUM2 and display the PRODUCT,DIFFERENCE,QUOTIENT, SUM of the two numbers
import java.util.Scanner;

class apples{
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
System.out.println("Select one of the following (absolute,ceil,floor,max,min,power,squareroot): ");
String code = scan.nextLine();
if (code.contains("absolute"));
System.out.println("Enter a number to get absolute value: ");
double num1 = scan.nextDouble();
System.out.println(Math.abs(num1));

}
}

Hey, this is the question I have, I want to be able to output and/or input a decimal value, but I keep getting errors, how come?
LATEST TUTORIALS
APPROVED BY CLIENTS