total of two code use DRJAVA and make sure it is work code 1
total of two code
use DRJAVA and make sure it is work
code 1
import java.util.Scanner;
 import java.lang.Math;
class Lesson_22_Activity_One {
 public static void main(String[] args)
 {
1. Write the code to take a String and print it with one letter per line.
Sample run:
Enter a string:
 bought
 b
 o
 u
 g
 h
 t
code 2
import java.util.Scanner;
 import java.lang.Math;
class Lesson_22_Activity_One {
 public static void main(String[] args)
 {
Write the code to take a String and print it diagonally.
Sample run:
Enter a string:
 bought
 b
     o
         u
             g
                  h
                      t
Solution
Question 1:
Lesson_22_Activity_One.java
import java.util.Scanner;
 import java.lang.Math;
 class Lesson_22_Activity_One {
 public static void main(String[] args)
 {
    Scanner scan = new Scanner(System.in);
    System.out.println(\"Enter a string: \");
    String s = scan.next();
    for(int i=0; i<s.length(); i++){
        System.out.println(s.charAt(i));
    }
 }
 }
Output:
Enter a string:
 bought
 b
 o
 u
 g
 h
 t
Question 2:
Lesson_22_Activity_One.java
import java.util.Scanner;
 import java.lang.Math;
 class Lesson_22_Activity_One {
 public static void main(String[] args)
 {
    Scanner scan = new Scanner(System.in);
    System.out.println(\"Enter a string: \");
    String s = scan.next();
    for(int i=0; i<s.length(); i++){
        for(int j=0; j<i; j++){
        System.out.print(\" \");
        }
        System.out.println(s.charAt(i));
    }
 }
 }
Output:
Enter a string:
 bought
 b
 o
 u
 g
 h
 t


