NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package stringlesson;

import java.util.Scanner;
/**
*
* @author Felton
*/
public class Stringlesson {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String city; //declared only

city = new String ("Milton"); // instantiated
// (Primitivies are initialized! Objects are instantiated.)
// Or can do both: String city = new String ("Milton");

// Or can do: String name "Milton";
// Use " " for strings
String empty = " "; // Or String empty = " ";

// the length method gives the number (int) of characters in the String
int cityLength = city.length();

int middlelndex = cityLength/2;

// indexOf gives the index (int) of the first occurrence of the character
int firstlndex = city.indexOf('A'); // Use ' ' for chars

// substring (a, b) gives the characters from the ath index up to the bth index. Doesn't include the bth index!
String citySubstring = city.substring(0,4);

// this gives the characters from the 2nd character through the end of the string. Why length-I?
String citySubstring2 = city.substring(2, city.length() - 1);

// Or substring (a) gives the characters from the ath index through the end of the string
String citySubstring3 = city.substring(2);

System.out.println("The city is " + city);
System.out.println("The empty string is " + empty);
System.out.println("The city's length is " + cityLength);
System.out.println("The city's middle index is " + middlelndex);
System.out.println("The index of the first A is " + firstlndex);
System.out.println("The substring from O to 4 is " + citySubstring);
System.out.println("The substring from 2 is " + citySubstring2);
System.out.println(" Another way from 2 is " + citySubstring3);

Scanner scan = new Scanner(System.in);
System.out.println("Do you enjoy APCS? Enter Yes, Somewhat, or No.");

String answer = scan.nextLine();

if(answer.equalsIgnoreCase("Yes"))
System.out.println("Me Too!");
else if (answer.equalsIgnoreCase("Somewhat"))
System.out.println("Okay.");
else
System.out.println("Sad day.");

System.out.println("Please type your name: ");

String inName = scan.nextLine();

// ------- added features below

int nameLength = inName.length(); // length of name integer returning character amount

int nameIndex = inName.indexOf('a'); // index of first 'a'

String nameSubstring1 = inName.substring(0,1); // Substring of First Letter
String nameSubstring2 = inName.substring(1,inName.length()); // Substring of everything BUT the first letter
String nameSubstring3 = "ay"; // ay to add for pig latin



System.out.println("The length of your name is " + nameLength + " characters long");

// Some logic just for a cleaner output
if (nameIndex > 0) {
System.out.println("The index of the first a is " + nameIndex);
} else {
System.out.println("There is no index for the character 'a'");
}

System.out.println("Your name in pig latin is " + nameSubstring2 + nameSubstring1 + nameSubstring3);

System.out.println("Please type a grade: ");

int grade = scan.nextInt();

if (grade >= 90) {
System.out.println("You got an A!");
} else if ((grade >= 80) && (grade < 90)) {
System.out.println("You got a B!");
} else if ((grade >= 70) && (grade < 80)) {
System.out.println("You got a C!");
} else {
System.out.println("You got an F!");
}

}

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.