1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
ID: 3551471 • Letter: 1
Question
1
2
3
4
5
6
7
8
9
10
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
public class WhatzitRevisited {
public static void main(String[] args) {
int i = 50;
int j = 0;
while (i > 0) {
int k = whatzitTheFirst(i);
j = j + k;
i = i / 10;
System.out.println("Main Loop");
}
System.out.println("The final value is: "+j);
}
private static int whatzitTheFirst(int j) {
int i = 50;
int k = 5;
while (k < j) {
System.out.println("First Whatzit");
i = i - whatzitTheSecond(j);
k = k*10;
}
return i;
}
private static int whatzitTheSecond(int k) {
int j = 2;
int i = 0;
while (j > 0) {
System.out.println("Second Whatzit");
i = i + k;
j = j - 1;
}
return i;
}
}
*
**
***
****
1
2
3
4
5
6
7
8
9
10
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
public class WhatzitRevisited {
public static void main(String[] args) {
int i = 50;
int j = 0;
while (i > 0) {
int k = whatzitTheFirst(i);
j = j + k;
i = i / 10;
System.out.println("Main Loop");
}
System.out.println("The final value is: "+j);
}
private static int whatzitTheFirst(int j) {
int i = 50;
int k = 5;
while (k < j) {
System.out.println("First Whatzit");
i = i - whatzitTheSecond(j);
k = k*10;
}
return i;
}
private static int whatzitTheSecond(int k) {
int j = 2;
int i = 0;
while (j > 0) {
System.out.println("Second Whatzit");
i = i + k;
j = j - 1;
}
return i;
}
}
Explanation / Answer
1)
1. 16 to 24
2. 8 to 10
3. 26 to 35
2)
import java.util.Scanner;
public class Palindrome {
String reverse(String str)
{
String revStr;
revStr= new StringBuilder(str).reverse().toString();
return revStr;
}
Boolean checkPalindrome(String str)
{
String revStr=reverse(str);
if(str.equals(revStr))
return true;
else return false;
}
public static void main(String args[])
{
Palindrome p=new Palindrome();
Scanner s=new Scanner(System.in);
System.out.println("Enter String:");
String str=s.next();
Boolean c=p.checkPalindrome(str);
if(c==true)
System.out.println("String " "+ str +" " is Palindrome");
else
System.out.println("String " "+ str +" " is not Palindrome");
}
}
3)
import java.util.Scanner;
public class Palindrome {
String reverse(String str)
{
String revStr;
revStr= new StringBuilder(str).reverse().toString();
return revStr;
}
Boolean checkPalindrome(String str)
{
String revStr=reverse(str);
if(str.equals(revStr))
return true;
else return false;
}
void Print()
{
String str=null;
Boolean c=false;
while(c==false)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter String:");
str=s.next();
c=checkPalindrome(str);
if(c==false)
System.out.println("String " "+ str +" " is not Palindrome, Enter again");
else
System.out.println("Palindrome String is " "+ str +" " ");
}
}
public static void main(String args[])
{
Palindrome p=new Palindrome();
p.Print();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.