Please i need some help with this in Java! Input/Output Quiz 1. (25%) What would
ID: 3779117 • Letter: P
Question
Please i need some help with this in Java!
Input/Output Quiz
1. (25%) What would the output be of the following?
int a = 4;
double b = 2.3456;
int c = 7;
System.out.print(a);
System.out.println("Hello World");
System.out.printf(“The value is %.2f”, b);
Answer ___________________________________________________
___________________________________________________
___________________________________________________
2. (25%) Explain the difference between float and double data types?
Answer ____________________________________________________
____________________________________________________
3. (50%) Create a program that will read in an int variable from the keyboard. You will need to prompt the user to “Enter an integer”. You will also need to have a print statement that prints the int value.
Explanation / Answer
Answers:
1) Output:
4Hello World
The value is 2.35
2) difference between float and double data types:
Both are binary floating types i.e they both handles integers having decimal i.e for example: 3.25
float has single-precision 32-bit whereas double has double-precision 64-bit
Double is more precise than float i.e double could handle more numbers.
Compilers sees 4.2f as a float data type and 4.2 as a double data type.
3)
import java.util.Scanner;
public class HelloWorld{
public static void main(String []args){
//for taking input from the keyboard
Scanner input=new Scanner(System.in);
//variable to store integer value enetered by the user
int n;
//prompting user to enter an integer
System.out.println("Enter an integer : ");
n=input.nextInt();
//printing integer value
System.out.println("Int value : "+n);
}
}
/******OUTPUT***********
Enter an integer :
10
Int value : 10
*********OUTPUT***********/
/* Note:This code has been tested on eclipse,Please ask in case of any doubt,Thanks,God bless you. */