0% found this document useful (0 votes)
257 views

Java Sample Programs Hackerrank

This document introduces a Java challenge to print "Hello, World." and "Hello, Java." to the standard output. It provides code stubs and instructions to complete the main method by copying and pasting two print statements. The output format is also specified.

Uploaded by

Suresh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
257 views

Java Sample Programs Hackerrank

This document introduces a Java challenge to print "Hello, World." and "Hello, Java." to the standard output. It provides code stubs and instructions to complete the main method by copying and pasting two print statements. The output format is also specified.

Uploaded by

Suresh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Welcome to the world of Java! In this challenge, we practice printing to stdout.

The code stubs in your editor declare a Solution class and a main method. Complete

the main method by copying the two lines of code below and pasting them inside the

body of your main method.

System.out.println("Hello, World.");
System.out.println("Hello, Java.");
Input Format

There is no input for this challenge.

Output Format

You must print two lines of output:

1. Print Hello, World. on the first line.

2. Print Hello, Java. on the second line.

Sample Output

Hello, World.
Hello, Java.

Solution:

public class Solution {

public static void main(String[] args) {

System.out.println("Hello, World.");

System.out.println("Hello, Java.");

A palindrome is a word, phrase, number, or other sequence of characters which reads


the same backward or forward.(Wikipedia)
Given a string , print Yes if it is a palindrome, print No otherwise.

Constraints

  will consist at most  lower case english letters.

Sample Input

madam
Sample Output

Yes

Soution’

import java.io.*;

import java.util.*;

public class Solution {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

String A=sc.next();

boolean isTrue = true;

int i = 0;

int j = A.length()-1;

while (i<j)

if(A.charAt(i) != A.charAt(j))

isTrue = false;
i++;

j--;

if(isTrue)

System.out.println("Yes");

else

System.out.println("No");

/* Enter your code here. Print output to STDOUT. */

You might also like