1.Given three int variables that have been declared and given values , areaCode,
ID: 3542642 • Letter: 1
Question
1.Given three int variables that have been declared and given values , areaCode, exchange, and lastFour, write a String expression whose value is the String equivalent of each these variables joined by a single hyphen (-) So if areaCode, exchange, and lastFour, had the values 800, 555, and 1212, the expression 's value would be "800-555-1212". Alternatively, if areaCode, exchange, and lastFour, had the values 212, 867 and 5309 the expression 's value would be "212-867-5309".
2. Write a statement that reads a word from standard input into firstWord. Assume that firstWord. has already been declared as a String variable . Assume also that stdin is a variable that references a Scannerobject associated with standard input.
3.Assume that name and age have been declared suitably for storing names (like "Abdullah", "Alexandra" and "Zoe") and ages respectively. Assume also that stdin is a variable that references a Scannerobject associated with standard input. Write some code that reads in a name and an age and then prints the message "The age of NAME is AGE" on a line by itself, where NAME and AGE are replaced by the values read in for the variables name and age.
For example, if your code read in "Rohit" and 70 then it would print out "The age of Rohit is 70" on a line by itself. There should NOT be a period in the output .
Explanation / Answer
1.Given three int variables that have been declared and given values , areaCode, exchange, and lastFour, write a String expression
whose value is the String equivalent of each these variables joined by a single hyphen (-)
So if areaCode, exchange, and lastFour, had the values 800, 555, and 1212, the expression 's value would be "800-555-1212".
Alternatively, if areaCode, exchange, and lastFour, had the values 212, 867 and 5309 the expression 's value would be "212-867-5309".
String expression = Integer.toString(areaCode) + "-" + Integer.toString(exchange) + "-" + Integer.toString(lastFour);
2. Write a statement that reads a word from standard input into firstWord. Assume that firstWord.
has already been declared as a String variable . Assume also that stdin is a variable that references a Scannerobject associated with standard input.
firstWord = stdin.next();
3.Assume that name and age have been declared suitably for storing names (like "Abdullah", "Alexandra" and "Zoe") and ages respectively.
Assume also that stdin is a variable that references a Scannerobject associated with standard input. Write some code that reads in a name
and an age and then prints the message "The age of NAME is AGE" on a line by itself, where NAME and AGE are replaced by the values read in
for the variables name and age.
For example, if your code read in "Rohit" and 70 then it would print out "The age of Rohit is 70" on a line by itself.
There should NOT be a period in the output .
name = stdin.next();
age = stdin.nextInt();
System.out.println("The age of "+name+" is "+age);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.