The following code has at least 3 errors. Rewrite the code to fix the errors. Wr
ID: 3788540 • Letter: T
Question
The following code has at least 3 errors. Rewrite the code to fix the errors. Write code that will print the first and last characters of String y in alphabetical order on the same line. for example, if y is "unicorn", your code should print "m" Convert the binary number 10111 to both hexadecimal and decimal by hand. Covert the hexadecimal number IABEI to binary by hand. Convert the decimal number 99 to binary by land. Given that a = false and b = true, state the value of the following expressions?Explanation / Answer
1.
DoubleDemo.java
public class DoubleDemo {
public static void main(String[] args) {
double a=99.0;
int y=((int)a)*2;
System.out.println("a = " + a);
System.out.println("y = " + y);
}
}
Output:-
2.
javaDemo.java
public class javaDemo {
public static void main(String[] args) {
int j=2;
if(j<9)
System.out.println("j is small");
else
System.out.println("j is larger");
}
}
Output:-
3.
javaDemo2.java
import java.util.*;
public class javaDemo2{
public static void main(String[] args){
Scanner scan = new Scanner (System.in);
String word;
System.out.print("Please write one word: ");
word = scan.nextLine();
System.out.println();
String first = Character.toString(word.charAt(0));
String last = Character.toString(word.charAt(word.length()-1));
int c = first.compareTo(last);
if (c < 0) {
System.out.print(first);
System.out.print(last);}
else {
System.out.print(last);
System.out.print(first);}
}
}
Output:-
4.
Binary = 1 0111
Hexadecimal = 17
Decimal = 1*2^4+0+1*2^2+1*2^1+1*2^0= 23
5.
Hexadecimal = 1ABE1
Binary = 0001 1010 1011 1110 0001 = 00011010101111100001
6.
Decimal = 99
Binary = 1100011
(Hint divide 99 by 2 till reaches 0 or 1 and put remaining bit in reverse order)
7.
Hint:-javaDemo3.java
public class javaDemo3{
public static void main(String[] args){
boolean a = false;
boolean b = true;
System.out.println(a && false);
System.out.println(a && b || !a);
System.out.println(!!b);
System.out.println(!(!a && b));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.