Source Code
Session6.java
import java.util.*;
public class Session6 {
public static void main(String[] args) {
String myName = ""; // add your name
System.out.println("Session 6" + " - " + myName);
// Menu
System.out.println("Menu");
System.out.println("E1 - Example 1");
System.out.println("Q - Quit");
// setup Scanner
Scanner in = new Scanner(System.in);
System.out.print("Choice: ");
String choice = in.nextLine();
// switch choices
switch (choice) {
case "E1":
System.out.println("Example 1");
example1();
break;
case "E2":
System.out.println("Example 2");
example2();
break;
case "E3":
System.out.println("Example 3");
example3();
break;
case "E4":
System.out.println("Example 4");
example4();
break;
case "E5":
System.out.println("Example 5");
example5();
break;
case "E6":
System.out.println("Example 6");
example6();
break;
case "E7":
System.out.println("Example 7");
example7();
break;
case "Q":
System.out.println("Quitting..!");
break;
default:
System.out.println("Invalid Choice");
}
}
// example1 method
public static void example1() {
}
// example2 method
public static void example2() {
}
// example3 method
public static void example3() {
// create array
// save first value
// loop
// if it's not the last element, copy the next one over
// print
}
// example4 method
public static void example4() {
}
// example5 method
public static void example5() {
// create 2d array
// print 2D array via deepToString
// print the number of rows
// print the number of columns
// print using nested for loops
}
// example6 method
public static void example6() {
// declare constants
// create 2D array named seatingChart
// initialize the array elements
// print the array elements
// print the rows and columns
// using nested for loops, print the elements
}
// example7 method
public static void example7() {
int[][] grid = {
{ 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 }
};
}
}
CommandLineArgs.java
public class CommandLineArgs {
public static void main(String[] args) {
System.out.println("Number of arguments: " + args.length);
for (int i = 0; i < args.length; i++) {
System.out.println("Argument " + i + ": " + args[i]);
}
}
}
CommandLineExample.java
public class CommandLineExample {
public static void main(String[] args) {
int num1 = Integer.parseInt(args[0]);
int num2 = Integer.parseInt(args[1]);
int sum = num1 + num2;
System.out.println("Sum: " + sum);
}
}
Last updated