Java programming This is what I must use as the input This i

Java programming:

This is what I must use as the input
This is my output that needs to be debugged
This is what my \"expected output\" should be

Solution

Hi, I have modified your code according to expected output.

Please let me know in case of any issue.

import java.util.Scanner;

public class Lab6a {

  

   public static void main(String[] args) {

      

       // creating an Scanner Object

       Scanner sc = new Scanner(System.in);

      

       //1 getting line1 test

       String line1 = sc.nextLine();

      

       // 2. print line1

       System.out.println(line1);

      

       // 3 print each character of line1 on separate line

       for(int i=0; i<line1.length(); i = i+2)

           System.out.print(line1.charAt(i));

       System.out.println();

      

       // 4 print from second character and print first character at last

       for(int i=1; i<line1.length(); i++)

           System.out.print(line1.charAt(i));

       System.out.println(line1.charAt(0)); // printing first character at last

      

       // 5 print all character of line1 in uppercase

       System.out.println(line1.toUpperCase());

      

       // 6 getting another line

       String line2 = sc.nextLine();

      

       if(line1.compareTo(line2) > 0){// line1 > line2

           System.out.println(line2);

           System.out.println(line1);

       }

       else{ // line1 <= line2

           System.out.println(line1);

           System.out.println(line2);

       }

   }

}

/*

Sample run:

The rain in Spain

The rain in Spain

Teri nSan

he rain in SpainT

THE RAIN IN SPAIN

Stays mainly in the plain

Stays mainly in the plain

The rain in Spain

*/

Java programming: This is what I must use as the input This is my output that needs to be debugged This is what my \
Java programming: This is what I must use as the input This is my output that needs to be debugged This is what my \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site