
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
In netbeans using Java use a (for loop) to determine whether a word (string) entered by the user is a palindrome. The picture provided shows an example with a (while loop).
![+2345
package lab9;
2 import java.util.Scanner;
public class Palindromel
{
1
6
7
8
9
10
HERREGAAN
H
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 31 32 33 34 35 36 37 38 39 40 41 42 43
0-
public static void main(String[] args)
{
// Create a Scanner
Scanner input = new Scanner(System.in);
// Prompt the user to enter a string
System.out.print("Enter a string: ");
String s = input.nextLine();
// The index of the first character in the string
int low = 0;
// The index of the last character in the string
int high = s.length() - 1;
boolean isPalindrome = true;
while (low < high)
{
}
if (s.charAt(low) !=s.charAt(high))
{
}
isPalindrome = false;
break;
if (isPalindrome)
{
}
else
{
}
low++;
high--;
System.out.println(s + " is a palindrome");
System.out.println(s + " is not a palindrome");](https://content.bartleby.com/qna-images/question/4b17bd5b-54f9-4eb4-8579-a760e9fbe7f9/8148b45d-96c1-414d-820d-c770d8bbf54d/3w575kh_thumbnail.png)
Transcribed Image Text:+2345
package lab9;
2 import java.util.Scanner;
public class Palindromel
{
1
6
7
8
9
10
HERREGAAN
H
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 31 32 33 34 35 36 37 38 39 40 41 42 43
0-
public static void main(String[] args)
{
// Create a Scanner
Scanner input = new Scanner(System.in);
// Prompt the user to enter a string
System.out.print("Enter a string: ");
String s = input.nextLine();
// The index of the first character in the string
int low = 0;
// The index of the last character in the string
int high = s.length() - 1;
boolean isPalindrome = true;
while (low < high)
{
}
if (s.charAt(low) !=s.charAt(high))
{
}
isPalindrome = false;
break;
if (isPalindrome)
{
}
else
{
}
low++;
high--;
System.out.println(s + " is a palindrome");
System.out.println(s + " is not a palindrome");
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Validating User Input Summary In this lab, you will make additions to a Java program that is provided. The program is a guessing game. A random number between 1 and 10 is generated in the program. The user enters a number between 1 and 10, trying to guess the correct number. If the user guesses correctly, the program congratulates the user, and then the loop that controls guessing numbers exits; otherwise, the program asks the user if he or she wants to guess again. If the user enters a "Y", he or she can guess again. If the user enters "N", the loop exits. You can see that the "Y" or an "N" is the sentinel value that controls the loop. Note that the entire program has been written for you. You need to add code that validates correct input, which is "Y" or "N", when the user is asked if he or she wants to guess a number, and a number in the range of 1 through 10 when the user is asked to guess a number. Instructions Ensure the file named GuessNumber.java is open. Write loops…arrow_forwardIn Java, design a program that uses nested loops to display a multiplication table for numbers 1 through 12.arrow_forwardA for construct is a loop that processes a list of items. As a consequence, it continues to run as long as there are items to process. Is this statement true or false?arrow_forward
- C#Write a method MyMethod which takes an int parameter named x. This method calculates the sum of integers from 1 to x and returns the sum. Use a for loop.arrow_forwardTAKE A LIST OF STRING FROM THE USER AND COUNT THE NUMBER OF UNIQUE ELEMENTS WITHOUT USING THE FOR, WHILE, Do-WHILE LOOPS. PREFERRED PROGRAMMING LANGUAGE: JAVA/C++arrow_forwardjavascripts write a loop prints all three digits number in decreasing order (999 , 998 ,997,..,101,100)arrow_forward
- A loop should sum all inputs, stopping when the input is 0. If the input is 2 4 6 0, sum should end with 12. What should XXX, YYY, and ZZZ be? Choices are in the form XXX / YYY / ZZZ. intsum;int currVal;XXX;currVal = scnr.nextInt();while (YYY) {ZZZ;currVal = scnr.nextInt();}a. sum=0/currVal!=0/sum=sum+currVal b. sum=currVal/currVal==0/sum=currVal c. sum=1/currVal!=0/sum=sum+1 d. sum=scnr.nextInt()/currVal==0/sum=scnr.nextInt() JAVAarrow_forwardIn Coral Language please! Write a for loop that iterates 5 times. Each iteration: Put userNum to output. Then, put "," to output. Then, assign userNum with userNum multiplied by 4. Ex: If input is 2, then output is: 2,8,32,128,512,arrow_forwardPrimeAA.java Write a program that will tell a user if their number is prime or not. Your code will need to run in a loop (possibly many loops) so that the user can continue to check numbers. A prime is a number that is only divisible by itself and the number 1. This means your code should loop through each value between 1 and the number entered to see if it’s a divisor. If you only check for a small handful of numbers (such as 2, 3, and 5), you will lose most of the credit for this project. Include a try/catch to catch input mismatches and include a custom exception to catch negative values. If the user enters 0, the program should end. Not only will you tell the user if their number is prime or not, you must also print the divisors to the screen (if they exist) on the same line as shown below AND give a count of how many divisors there are. See examples below. Your program should run the test case exactly as it appears below, and should work on any other case in general. Output…arrow_forward
- A string is a palindrome if it is identical forward and backward. For example "anna", "civic", "level" and "hannah" are all examples of palindromicwords. Write a program that reads a string from the user and uses a loop to determine whether or not it is a palindrome. Display the result, including a meaningful output message.arrow_forwardJava program I need help creating a program that creates a Christmas tree. It has a method that accepts two parameters (one for the number of segments and one for the height of each segment). The left tree has 3 segments with a height of 4 and the right one has two segments with a height of 5. Can you explain how the for loops would work?arrow_forwardin C#arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education