-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExBasicIO1.java
More file actions
63 lines (48 loc) · 2.81 KB
/
ExBasicIO1.java
File metadata and controls
63 lines (48 loc) · 2.81 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.util.Scanner;
public class ExBasicIO1{
public static void main(String[] args){
System.out.println("Success is when your \"signature\" becomes \"autograph\"");
System.out.println("\\n");
System.out.println("%%");
System.out.println("\\");
Scanner obj = new Scanner(System.in); //Read an integer and print
long n = obj.nextLong();
System.out.println(n);
char ch = obj.next().charAt(0); //Accept a character and print
System.out.println(ch);
long n1 = obj.nextLong(); //first number as a 5-digit number
long n2 = obj.nextLong(); //second number with 5 width space
System.out.printf("%05d\n",n1);
System.out.printf("%5d",n2);
long val = obj.nextLong(); //print the number along with its sign
System.out.printf("%+d", val);
char character = obj.next().charAt(0); //Accept a character and print its corresponding ASCII value
int ascii = character;
System.out.println(ascii);
int nchar = obj.nextInt(); //Accept an integer value and print the corresponding character
System.out.println(nchar+":"+(char)nchar);
double decimal = obj.nextDouble(); //Round off floating point value with accurate to 2 decimal places.
System.out.printf("%.2f",decimal);
double dec = obj.nextDouble(); //print it with 20 width space and round off to 4 decimal places.
System.out.printf("%20.4f",dec);
double Float = obj.nextDouble(); //print the floating point value according to the precision given.
int precision = obj.nextInt();
String format = "%."+precision+"f";
System.out.printf(format,Float);
double inputValue = obj.nextDouble(); //floating point value to its nearest integer value
long input = Math.round(inputValue);
System.out.println(input);
String hex = obj.next(); // hexadecimal value to decimal value
long decimalValue = Long.parseLong(hex.substring(2), 16);
System.out.println(decimalValue);
float expo = obj.nextFloat(); //float value to its exponential form
System.out.printf("%e", expo);
int value = obj.nextInt(); //decimal to hexadecimal number
String hexValue = Integer.toHexString(value);
System.out.println(hexValue);
double floatVal = obj.nextDouble(); //remove trailing zeros.
String floatStr = Double.toString(floatVal);
String formattedVal = floatStr;
System.out.println(floatStr);
}
}