0% found this document useful (0 votes)
48 views4 pages

Java Feladat

The document checks if a given string is a palindrome by comparing it to its reverse; it reads in a string, converts it to a StringBuffer, reverses it, converts back to string, and compares to the original using equalsIgnoreCase, printing "Yes" if they are equal or "No" if not.

Uploaded by

gogo
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)
48 views4 pages

Java Feladat

The document checks if a given string is a palindrome by comparing it to its reverse; it reads in a string, converts it to a StringBuffer, reverses it, converts back to string, and compares to the original using equalsIgnoreCase, printing "Yes" if they are equal or "No" if not.

Uploaded by

gogo
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/ 4

Scanner sc=new

Scanner(System.in);
int n=sc.nextInt();
String ans="";
if(n%2==1){
ans = "Weird";
}
else {
if (n >= 2 && n <= 5) {
ans = "Not Weird";
} else if (n >= 6 && n <= 20)
{
ans = "Weird";
} else {
ans = "Not Weird";
}

//Complete the code

}
System.out.println(ans);

03 - Loops I
Objective
In this challenge, we're going to use loops to help us do some simple math.

Task
Given an integer, n , print its first 10 multiples. Each multiple n x i (where 1 <= i <=
10) should be printed on a new line in the form: 'n x i = result'.

Input Format
A single integer, n.

Constraints
0 <= n <= 50

Output Format
Print 10 lines of output; each line i (where 1 <= i <= 10) contains the result of n x i in
the form: 'n x i = result'.
Scanner scanner = new Scanner(System.in);

int N = scanner.nextInt();

scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?");

for(int i = 1; i <= 10; i++){

System.out.println(N + " x " + i + " = " + N*i);

scanner.close();

Java Loops Objective: In this challenge, we're going to use loops to help us do some simple
math.Task:Given an integer,N , print its first 10 multiples. Each multiple N x i (where 1 <= i <= 10)
should be printed on a new line in the form: N x i = result.Input Format: A single integer,
N.Constraints:2 <= N <= 20Output Format:Print 10 lines of output; each line i (where 1 <= I <= 10)
contains the result of N x i in the form: N x i = result.Sample Input: 2Sample Output: 2 x 1 = 22 x 2 =
42 x 3 = 62 x 4 = 82 x 5 = 102 x 6 = 122 x 7 = 142 x 8 = 162 x 9 = 182 x 10 = 20*/ import
java.io.*;import java.math.*;import java.security.*;import java.text.*;import java.util.*;import
java.util.concurrent.*;import java.util.regex.*; public class Solution { private static final Scanner
scanner = new Scanner(System.in); public static void main(String[] args) { int N = scanner.nextInt();
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); for(int i = 1; i <= 10; i++){ System.out.println(N +
" x " + i + " = " + N*i); } scanner.close(); }} /*Input: 2 Your Output:2 x 1 = 22 x 2 = 42 x 3 = 62 x 4 = 82 x
5 = 102 x 6 = 122 x 7 = 142 x 8 = 162 x 9 = 182 x 10 = 20 Expected Output:2 x 1 = 22 x 2 = 42 x 3 = 62 x
4 = 82 x 5 = 102 x 6 = 122 x 7 = 142 x 8 = 162 x 9 = 182 x 10 = 20*/

04 - 1D Array
Task
Create an array, a, capable of holding n integers.
Using a loop, save each sequential value to its corresponding location in the array.
For example, the first value must be stored in a0, the second value must be stored
in a1, and so on.
Good luck!

Input Format
The first line contains a single integer, n, denoting the size of the array.
Each line i of the n subsequent lines contains a single integer denoting the value of
element ai.

Output Format
Loop through array a and print each sequential element on a new line.
 Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
int[]a=new int[n];
//inserting values at each ith indices
for(int i=0;i<n;i++)
{
    a[i]=scan.nextInt();
}
        scan.close();

        // Prints each sequential element in array a


        for (int i = 0; i < a.length; i++) {
            System.out.println(a[i]);

05 - Substring
Task
Given a string, s, and two indices, start and end, print a substring consisting of all
characters in the inclusive range from start to end - 1. You'll find the String
class's substring method helpful in completing this challenge.

Input Format
The first line contains a single string denoting s.
The second line contains two space-separated integers denoting the respective
values of start and end.

Constraints

 1 <= |s| <= 100


 0 <= start <= end <= n
 String s consists of letters of the Hungarian alphabet and punctuation marks

Output Format
Print the substring in the inclusive range from start to end - 1.

Scanner inputString = new Scanner(System.in);


String s = inputString.nextLine();
int start = inputString.nextInt();
int end = inputString.nextInt();

System.out.println(s.substring(start, end));
palindrome

Scanner sc=new Scanner(System.in);


String A=sc.next();

if(A.equalsIgnoreCase(new StringBuffer(A).reverse().toString()))
System.out.println("Yes");
else
System.out.println("No");

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy