Solution: Update your settings
Here's how to update your settings (from here):
Option 1:
Open the Settings editor:
On Windows/Linux - File > Preferences > Settings
On macOS - Code > Preferences > Settings
or use the keyboard shortcut (Ctrl+,).
Check the following box:
Extensions > Python > Terminal: Execute In File Dir.
or use the Search bar and type this setting id python.terminal.executeInFileDir.
Option 2:
Locate and open the user settings file:
Windows %APPDATA%\Code\User\settings.json
macOS $HOME/Library/Application Support/Code/User/settings.json
Linux $HOME/.config/Code/User/settings.json
Add this line: "python.terminal.executeInFileDir": true
Java API (documentation)
Use Integer.toString to convert an int to a String, as in:
String eight = Integer.toString( 8 );
Use Integer.parseInt to convert a String to an int, as in:
int num8 = Integer.parseInt( "8" );
Use the equals instance method to test "logical" equality between objects, particularly String objects, as in:
String greeting = "hi";
greeting += " there";
System.out.println( greeting.equals( "hi there" ) );
System.out.println( greeting == "hi there" );
We can use the general List "interface" (you can think of this as a type) and create a new list by picking the ArrayList "implementation."
You would learn more about the interface/ADT and implementation relationship and choices in Data Structures. For this course, just take this as sample code to adapt.
import java.util.List;
import java.util.ArrayList;
public class SampleSequentialData
{
public static void sampleList()
{
// demonstrates a (dynamically sized) List, implemented with an ArrayList
List<String> weekendDays; // declare a variable of type List that will hold String values
// create an instance of an ArrayList that is empty to initialize the weekendDays list
weekendDays = new ArrayList<String>();
// add a String element to the (end of the) list
weekendDays.add( "Saturday" );
// add another String element to the (end of the) list
weekendDays.add( "Sunday" );
// use the built-in toString method to print the elements of the list
System.out.println( "Weekends are: " + weekendDays.toString() );
// use a for loop to walk the list and print the elements
for ( int i = 0; i < weekendDays.size(); i++ )
{
// use the get instance method to obtain the value at index i
String currentValue = weekendDays.get( i );
System.out.println( currentValue );
}
// we can ask if the list is empty
boolean noWeekends = weekendDays.isEmpty();
System.out.println( "Are there no weekends? " + Boolean.toString( noWeekends ) );
}
public static void sampleArray()
{
// demonstrates a (fixed length) array
String[] weekdays = {"Monday","Tuesday","Wednesday","Thursday","Friday"};
for ( int i = 0; i < weekdays.length; i++ )
{
System.out.print( weekdays[i] + ", " );
}
System.out.println( "" );
weekdays[0] = "Mon";
System.out.println( "And now... weekdays are: ");
for ( int i = 0; i < weekdays.length; i++ )
{
System.out.print( weekdays[i] + ", " );
}
System.out.println( "" );
}
public static void main( String[] args )
{
sampleList();
sampleArray();
}
}
import java.util.Scanner;
public class SampleUserInput {
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in); // System.in is a standard input stream
System.out.print( "Enter your name: " ); // print a prompt
String userName= sc.nextLine(); // wait for and accept input
System.out.println( "Hello, " + userName + "!" );
sc.close(); // close the scanner
}
}