Answered step by step
Verified Expert Solution
Question
1 Approved Answer
My professor gave this practice as a study guide for the test, could you please solve it, so I could practice knowing the right answers.THanks
My professor gave this practice as a study guide for the test, could you please solve it, so I could practice knowing the right answers.THanks a lot.
package pT1Practice; // A reference for use during the practical 1 test. It will be printed as // part of the test. This is just a syntax reference- you should be able // to use code such as this to solve problems // Allow this program to use the code in the Scanner package. import java.util.Scanner; // A class contains methods and instance variables. public class TestReferencet // This method adds 1 to an int passed to it as an argument. public static int addOne (int num) return num + 1; public static void main(String[] args) int x 1; // Declare x as an int and assign 1 to it. String s"David"; // Declare a String s and assign a value. Scanner scannew Scanner "David"); // Make a Scanner object. scan.next); // get the next token scan. hasNext ); II See if there is a token. scan.nextInt: // get the next token if it is an int number. scan. hasNextInt); II See if there is an int token available. // Demonstrate an if with a condition and true and false actions System.out.println (" is 1"); else System.out.println("x is not 1"); // Test equality of value of two String. Get a token from the Scanner. if (s.equals(scan.next))) System.out.println("David is David"); while (x , , Logical operators and: && or not: ! 2A package practicalTestl; import javautil.Scanner; Sample problems for practical test 1. During the test, you would be asked to fill in the methods defined below public class PT1 Practice Add 1 to the number parameter @param number @return the value in number plus one Example: addOne(2) would evaluate to 3 public static int addOne(int number) return 0; I change this Use the age parameter to determine what value to return. The categories are age
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started