Java Feladat
Java Feladat
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";
}
}
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])?");
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();
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
Output Format
Print the substring in the inclusive range from start to end - 1.
System.out.println(s.substring(start, end));
palindrome
if(A.equalsIgnoreCase(new StringBuffer(A).reverse().toString()))
System.out.println("Yes");
else
System.out.println("No");